I’m looking to geolocate my server requests by continent.
Basically, after doing some initial research, it seems that there are 3 approaches: 1) using the geolocation provided by browsers (but I think noone seriously click “Yes” when the browser is asking permission to use geolocation); 2) getting a list of IP addresses, putting that list in a database on your server and then every time a request comes in, read from this DB; I’d hate to have have to hit the DB at every request. 3) make an HTTP call to an external server to get the location; that could even be slower than 2).
Basically, I don’t really care to know exactly where the users are, I just need to know which continent they’re on: North Armerica, Europe…
Is there a way to do this that doesn’t require any user interaction and doesn’t require reading a DB on every request? When I go to http://www.intel.com I get automatically rerouted to the French site; how do they do that?
Thanks for your suggestions.
There are some free and some commercial database that can tell you from the ip, where is coming from.
The free database from maxmind [*]: http://dev.maxmind.com/geoip/geolite
and two commercial:
http://www.ip2location.com
http://www.maxmind.com
In this site you can also find asp.net examples on how you can use that data, but also they have other free services that you can use and see where the use is come from.
Get api samples together with the database from: http://www.maxmind.com/download/geoip/
If only the country is what you need for then this database file
http://www.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip
contains only the country, and is small compared with the rest.
How this works in few words: The database is in format of:
the long numbers are the translation of the ip. So you read the IP of your user and then with a function you convert it to long and then you search the database, where is this long number fits.
So if you add them in database then you index the database on this long numbers and look where the ip is in as:
Its good to cache the result on a session variable and not search again and again on every page request.
[*] A big thanks to maxmind that still release the free database together with the commercial.