0

Problem:

I would like to detect location of user who came to my website.

I am thinking about following:

  1. "Somehow detect" if user uses a mobile device with GPS module. If yes, then somehow (maybe using google maps) translate it from coordinates to "City, Street".
  2. If first option fails, then somehow search for geo location of $_SERVER['REMOTE_ADDR'].

Questions

  1. I assume that with first option I could retrieve exact address of user. With second option I am able to detect city in which provider operates. So if I want, for example, to display nearest bakery shops to user, I could not relay on that.
  2. Is this code suitable for first option location detection in web browser ?
  3. This Getting the location from an IP address seems to be best for the second option, am I right?
Community
  • 1
  • 1
Michal
  • 1,955
  • 5
  • 33
  • 56
  • 1
    [Geolocation API](https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation) – adeneo Jul 01 '14 at 11:47

1 Answers1

1

you can get the device a user is using by adding this simple php script. Im using it in production on www.arena.co.ke

Download the script here... and remove the .zip extension. (added as a simple hack to enable donloading)

about GPS detection, you might have to find your self a js library for that. google abit