Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
    
4  
You should ask this question on StackOverflow.com instead. –  Jonas Jul 22 '10 at 22:56
6  
I think that there will always be crossover questions that will be appropriate to both. But the answers here with a GIS perspective may be different to answers there with a programming perspective. –  JamesRyan Jul 23 '10 at 8:55
add comment

9 Answers

up vote 12 down vote accepted

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>
share|improve this answer
add comment

The location you can infer from IP isn't very reliable (i.e. it kinda works sometimes).

If you want a reliable location, consider the geolocation API that is part of HTML5. Note, however, that not all web browsers support it (yet).

share|improve this answer
1  
+1 for HTML5. You could always use both - if geoloation API fails, fall back on IP. More website support means more pressure on browser vendors to support better technologies. –  naught101 May 20 '12 at 14:08
    
But we're talking about "visitor's rough location", so this may not be what you want. An important point is that HTML5 geolocation will pop-up a scary looking confirmation prompt. Yes the location will typically be much more exact ...but only after the visitor agrees to the confirmation prompt. –  Harry Wood Nov 20 '12 at 16:01
add comment

An option that focuses on mobile support, though also works well on most desktop browsers (except for IE in my experience), is the Geo-Location-Javascript package which wraps the HTML5 GeoLocation API Sean mentioned. I found the mobile browser support pretty poor for the HTML5 API (not surprising, though, since it's still in draft) so that's why I went with this package.

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.

share|improve this answer
add comment

You can use this url and pass it an IP address. http://api.hostip.info/get_html.php?ip=84.32.32.44

share|improve this answer
add comment

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.

share|improve this answer
add comment

Google analytics provide basic maps and statistics on your visitor's location. Of course, you have to share this information with Google...

share|improve this answer
4  
that would let me report on visitors but not tailor my content on the fly by location –  JamesRyan Jul 23 '10 at 16:34
add comment

ipinfodb.com is good but they are currently offline :(

I am using that to my api. It is great for my weather, but i don't know now it has been offline since yesterday.

share|improve this answer
1  
Thank you for your reply. Did you notice that @FMark has already described this service in an earlier reply in this thread? –  whuber May 16 '11 at 12:54
    
its not a critism about ipinfodb but i had problems before with my currency converter and currency api tool, tried to use that to auto determine the location and could give them a direct location associated with currency but ;S had a lots of issue site was 3 days offline, or some connection error or tales a lot of time loading which could affect your Site Performance, and google dont want that... –  WorldwideCenter Main Jul 27 '11 at 22:11
    
Infodb seems great, tried it for months now.. do they have limit? i mean visitors per day? –  user3894 Aug 9 '11 at 16:40
add comment

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/ )

share|improve this answer
add comment

try to use google analytics, that gives you all data related with you homepage, where it come, how many UNIQUE visitors you have and wher

share|improve this answer
    
The question is about providing custom content not analytics. –  JamesRyan Jun 10 '11 at 8:52
add comment

protected by whuber May 10 '13 at 13:16

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.