Recommend this page to a friend! |
All requests ![]() |
> | Detect user's location at the street ... | > | Request new recommendation | > | ![]() |
> | ![]() |
by PHP5Matters - 9 years ago (2015-08-04)
+7 | 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 - 9 years 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 - 9 years 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 - 9 years 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 |
the precision at the street level only depending of latitude and longitude i suggest this package which is above all a very simple way without special programmer's knowledge to , include a ip location feature in your app.Of course you can use ajax to request a PHP script using this package... |
+4 |
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 | |
|