PHP Classes
elePHPant
Icontem

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

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  All requests RSS feed  >  Detect user's location at the street level  >  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 - 6 months ago (2015-08-04)

Web site user's location

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

+2

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 - 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. Picture of Dave Smith 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. Picture of Manuel Lemos 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.

Ask clarification

1 Recommendation

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