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?
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:
This will return an XML file containing latitude and longitude, that looks like:
<Response> <Ip>18.104.22.168</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>
The results from moblie devices are quite good over cell and WiFi connections (and GPS if the device has it). Desktop browsers report a pretty coarse-grained position comparable to other services.
You can use this url and pass it an IP address. http://api.hostip.info/get_html.php?ip=22.214.171.124
Quova http://www.quova.com/ also has a service. I spoke to them yesterday at GeoLoco. According to the them (so take it with a grain of salt) they say they are much better internationally than MaxMind. They are about equal in North America.
Be aware that for mobile phones the IP will probably map to wherever the Operator has their gateway to the internet. You can also try using - http://www.loc-aid.com/ if you are targeting mobile phones.
Google analytics provide basic maps and statistics on your visitor's location. Of course, you have to share this information with Google...
If you want to provide them content or ads based on their geographical location you can't rely to take the location data from the device. Even they are on mobile phones there is a high chance that they have GPS and wifi turned off, and they have to give their consent to share the location.
It is like: "Hey, can you share your location with me so I can give you content and ads that I think are most related to your geographic location?" Response: "No! Give me the best content and ads you have out there"
The only way to find the location without asking them for permission is trough their IP Address. You can install a database on your own server and query it to find the location of an IP Address or to use an external API that you have to query and get the results. I am using ipgp geolocation api and working great. ( http://www.ipgp.net/ip-address-geolocation-api/ )
protected by whuber♦ May 10 '13 at 13:16
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?