-2

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?

2

3 Answers 3

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;
            }
-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".

1
  • Why the downvote? My answer has nothing to do with JavaScript! Apr 25, 2016 at 11:30
-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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.