I am developing a website using ASP.NET MVC, how can I get the current location (Country, city, district, lat-lng geolocation) of each visitor browses my website depending on IP address?
Asked
Active
Viewed 1,096 times
-2
-
Welcome to Stack Overflow. Please read [ask] and share your research. You're not the first person asking this question. – CodeCaster Apr 20 '16 at 11:18
-
1Possible duplicate of [How to get visitor's location (i.e. country) using javascript geolocation](http://stackoverflow.com/questions/3489460/how-to-get-visitors-location-i-e-country-using-javascript-geolocation) – CodeCaster Apr 20 '16 at 11:22
3 Answers
1
It's possible to get location by using IP address of visitor. Use web-service provided by ipinfodb.com :
string url = string.Format("https://api.ipinfodb.com/v3/ip-city/?key={0}&ip={1}&format=json", APIKey, ipAddress);
using (WebClient client = new WebClient())
{
string json = client.DownloadString(url);
Location location = new JavaScriptSerializer().Deserialize<Location>(json);
return location;
}

Bassel
- 133
- 2
- 7
-1
There are several services out there that can do this. Try, for example, this one: http://geoip.nekudo.com. An example: http://geoip.nekudo.com/api/8.8.8.8 Look for "ip geolocation rest api".

Ricardo Peres
- 13,724
- 5
- 57
- 74
-1
There are many geo-localization service you can use. For example, I do this way.
Put this tag inside your main .html page:
<script type="text/javascript" src="https://l2.io/ip.js?var=userIp"></script>
Than you will find a global variable called userIp
with the calling ip address.
Than you can use any geolocation tool to get all the information you need.

Luca Ghersi
- 3,261
- 18
- 32