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?

  • 5
    You should ask this question on StackOverflow.com instead.
    – Jonas
    Jul 22, 2010 at 22:56
  • 7
    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, 2010 at 8:55

8 Answers 8


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:

  <CountryName>United States</CountryName>
  • 5 years afterwards.... Can someone update this answer? Post a new answer? Aug 14, 2015 at 14:36
  • 5 years later most geoid systems are useless because they're unable to locate mobile users correctly... Sep 4, 2015 at 12:22

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

  • 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, 2012 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, 2012 at 16:01

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.


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


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

  • 4
    that would let me report on visitors but not tailor my content on the fly by location
    – JamesRyan
    Jul 23, 2010 at 16:34

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.

  • 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, 2011 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...
    – jarauzes
    Jul 27, 2011 at 22:11
  • Infodb seems great, tried it for months now.. do they have limit? i mean visitors per day?
    – user3894
    Aug 9, 2011 at 16:40

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

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