How to detect country / location of visitor? [duplicate]

Solution 1:

NetImpact provide a free API for geolocation lookup by IP, ProgrammableWeb also has a roundup of GeoIP lookup providers. This involves a small amount of latency while your application completes an API call (unless your application can use a non-blocking call) but is the least intrusive manner of detecting a visitor's country of origin.

Solution 2:

The browser header just tells you what language the user wants to see. A Spanish-speaking person on a business trip to Japan probably wants to see websites in Spanish.

I think you can use reverse-IP services to make a guess, but if it's for commerce purposes I think you have to ask the user to tell you.

Similarly with geo-location: the physical position of the computer may or may not be relevant to the needs of the user browsing the site.

Solution 3:

Have a look at this page on the Google Maps API: http://code.google.com/apis/maps/documentation/javascript/basics.html#DetectingUserLocation