Recommend this page to a friend! | Stumble It! | Bookmark in del.icio.us |
All requests | > | Detect user's location at the street level | > | Request new recommendation | > | Featured requests | > | No recommendations | ||
by PHP5Matters - 6 months ago (2015-08-04) location user
+2 | I would like to detect the current web site user's location i.e. street address, colony, etc using JavaScript and PHP. |
1. by Manuel Lemos - 6 months ago (2015-08-04) Reply
Well with JavaScript alone you cannot do much except for sending AJAX requests to some public API.
What you can do is to use JavaScript to send AJAX requests to a PHP script that will actually try to find the approximate user location associated to the user IP address.
There some solutions for that in PHP, some require calling a remote API, others require searching a database file of IP address ranges.
There are free solutions for each but the most accurate and up to date are paid.
2. by Dave Smith - 6 months ago (2015-08-04) in reply to comment 1 by Manuel Lemos Comment
And I do not know of any that get down to the street level.
3. by Manuel Lemos - 6 months ago (2015-08-05) in reply to comment 2 by Dave Smith Comment
Yes, from the IP address you cannot get much more accuracy than city level and even at that level many API may be very inaccurate.
What you can do is check if the support of the HTML5 geolocation is enabled. If so, you can get the approximate coordinates from your device GPS or whatever your browser supports.
Then you can call the Google Maps API for instance to a more accurate location at least near the street level.
+3 | by Manuel Lemos 11100 - 6 months ago (2015-08-05) Comment This class provides the solution described above by generating HTML with JavaScript to get the user location coordinates and then call Google Maps API to get the approximate street address. Most of the job is done in JavaScript but the class generates the necessary JavaScript code for that. It will not work if the user device cannot figure its location or the user does not allow to share his location, but otherwise it is still useful. |
Recommend package | |
|