Click here to Skip to main content
15,881,281 members
Articles / Web Development / ASP.NET
Tip/Trick

LocatorHQ - Get Country/Region/City From IP Address

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
14 Jan 2014CPOL 14.7K   8   4
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:

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Other Other
Programming is an art.

Comments and Discussions

 
QuestionJust like any amateur API.... Pin
Axel Rietschin15-Jan-14 15:44
professionalAxel Rietschin15-Jan-14 15:44 
GeneralNice, but not at all Pin
Luis Oliveira 196615-Jan-14 0:01
Luis Oliveira 196615-Jan-14 0:01 
GeneralMessage Closed Pin
15-Jan-14 2:42
mvaadriancs15-Jan-14 2:42 
GeneralRe: Nice, but not at all Pin
Luis Oliveira 196615-Jan-14 9:17
Luis Oliveira 196615-Jan-14 9:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.