[GIS] How to determine the location of a visitor to the website

geolocationmobile

If I want to provide a website with location appropriate content, what ways can I use to find the visitor's rough location using their IP or header information?

Best Answer

Firstly, you should know that the accuracy of these services is, and always will be, low.

MaxMind Geolite city is free. If it is not good enough, you can apparently upgrade to a more accurate paid-version. I can't speak for the quality of the paid version, as I have never used it.

If you like your SQL, download the CSV version. Load it into your database of choice, and query away.

The faster and space-efficient option is to download the file binary blob version of the same database, and then use a language specific API from the same website to query it.

Alternatively, I have found ipinfodb.com to be useful. Query is by simple HTTP GET. For example, to geolocate stackoverflow.com try:

http://ipinfodb.com/ip_query.php?timezone=false&ip=69.59.196.211

This will return an XML file containing latitude and longitude, that looks like:

<Response>
  <Ip>69.59.196.211</Ip>
  <Status>OK</Status>
  <CountryCode>US</CountryCode>
  <CountryName>United States</CountryName>
  <RegionCode>41</RegionCode>
  <RegionName>Oregon</RegionName>
  <City>Corvallis</City>
  <ZipPostalCode>97333</ZipPostalCode>
  <Latitude>44.4698</Latitude>
  <Longitude>-123.343</Longitude>
</Response>