Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

LocatorHQ - Get Country/Region/City From IP Address

0.00/5 (No votes)
14 Jan 2014 1  
Easily get Country, Region and Citry of web visitors from their IP address.

Register FREE Username and API key at http://www.locatorhq.com[^]

Then, get the data by accessing: 

http://api.locatorhq.com/?user=<username>&key=<apikey>&ip=<ipaddress>  

Example:

http://api.locatorhq.com/?user=john3041&key=27364b3d6060c9e0738754c9be60908ab00ac7&ip=64.233.191.255 

Data return in this format:

<countryCode>,<countryName>,<region>,<city>,<latitude>,<longitude>

Example:

US,United States,California,Mountain View,34.305,-86.2981,64.233.191.255 

Data format suports XML and JSON, just add a parameter of format:

http://api.locatorhq.com/?user=<username>&key=<apikey>&ip=<ipaddress>&format=xml 
http://api.locatorhq.com/?user=<username>&key=<apikey>&ip=<ipaddress>&format=json

For C# ASP.NET, you can get the data at code behind by using WebClient.

Example:

string url = "http://api.locatorhq.com/?user=john3041&key=27364b3d6060c9e0738754c9be60908ab00ac7&ip=64.233.191.255";
WebClient wc = new WebClient();
byte[] ba = wc.DownloadData(url);
string text = System.Text.Encoding.UTF8.GetString(ba); 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here