PHP Classes

Detect user's location at the street level: Web site user's location

Recommend this page to a friend!
  All requests RSS feed  >  Detect user's location at the street ...  >  Request new recommendation  >  A request is featured when there is no good recommended package on the site when it is posted. Featured requests  >  No recommendations No recommendations  

Detect user's location at the street level

Edit

Picture of PHP5Matters by PHP5Matters - 8 years ago (2015-08-04)

Web site user's location

This request is clear and relevant.
This request is not clear or is not relevant.

+6

I would like to detect the current web site user's location i.e. street address, colony, etc using JavaScript and PHP.

  • 1 Clarification request
  • 1. Picture of Manuel Lemos by Manuel Lemos - 8 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. Picture of Dave Smith by Dave Smith - 8 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. Picture of Manuel Lemos by Manuel Lemos - 8 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.

Ask clarification

2 Recommendations

Very Simple IP Details: Get IP address location and Google Maps image

This recommendation solves the problem.
This recommendation does not solve the problem.

+2

Picture of zinsou A.A.E.Moïse by zinsou A.A.E.Moïse package author package author Reputation 5840 - 6 years ago (2017-08-20) Comment

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...


Localization class: Detect user location using HTML 5 API or GeoIP API

This recommendation solves the problem.
This recommendation does not solve the problem.

+3

Picture of Manuel Lemos by Manuel Lemos Reputation 23325 - 8 years 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
: 
: