34

Is it possible to get the longitude and latitude value from IP address in asp.net? If it is possible, please let me know how can I get this.

casperOne
  • 73,706
  • 19
  • 184
  • 253
Zerotoinfinity
  • 6,290
  • 32
  • 130
  • 206

6 Answers6

33

MaxMind Geolite city is free. If it is not good enough, you can apparently upgrade to a more accurate paid-version. I can't speak for the quality of the paid version, as I have never used it.

If you like your SQL, download the CSV version. Load it into your database of choice, and query away.

The faster and space-efficient option is to download the file binary blob version of the same database, and then use the C# class to query it.

Alternatively, I have found ipinfodb.com to be useful. Query is by simple HTTP GET. For example, to geolocate stackoverflow.com try:

http://ipinfodb.com/ip_query.php?timezone=false&ip=69.59.196.211

This will return an XML file containing latitude and longitude, that looks like:

<Response>
  <Ip>69.59.196.211</Ip>
  <Status>OK</Status>
  <CountryCode>US</CountryCode>
  <CountryName>United States</CountryName>
  <RegionCode>41</RegionCode>
  <RegionName>Oregon</RegionName>
  <City>Corvallis</City>
  <ZipPostalCode>97333</ZipPostalCode>
  <Latitude>44.4698</Latitude>
  <Longitude>-123.343</Longitude>
</Response>

Some VB.NET sample code is available at http://forum.ipinfodb.com/viewtopic.php?f=7&t=269

fmark
  • 57,259
  • 27
  • 100
  • 107
  • 1
    They require registration to get an API key since this post, but it's free and relatively painless. – mrbellek Feb 06 '12 at 08:35
  • I have been using this service for free with a credit on the page and its been rock solid. – James Westgate Feb 28 '13 at 10:28
  • Provided ipinfodb.com query does not work anymore. Furthermore, even their paid service has factual errors. For example, it lists Belgrade, the capitol of Serbia as being part of Vojvodina province which is completely incorrect. – Igor Levicki Feb 08 '14 at 16:36
2

You can use a service such as: http://freegeoip.appspot.com/

It will not be completely accurate.

Here is a tutorial on consuming the service using ASP.Net.

dugas
  • 12,025
  • 3
  • 45
  • 51
  • Hi Thedugas, http://freegeoip.appspot.com/ is not working properly and I have implemented the same thing it is throwing an error 503. Might be this service is stopped. :( Please let me know if you have other thoughts. Thanks again for your reply. – Zerotoinfinity Apr 18 '10 at 21:02
2

Try IPInfoDB which, as far as I know, is free.

They provide downloadable databases, but the easiest solution seems to be the XML api. Examples provided are for php, but I'm sure it's equally accessible with ASP.Net.

Shawn Chin
  • 84,080
  • 19
  • 162
  • 191
1

http://www.iptolatlng.com/ works well for me because it gives me JSON output raw which I need for this app I'm working on.

mikewhit
  • 121
  • 5
0

There is another one as well: http://www.hostip.info/index.html

It has an api, might be interesting for you to have a look at.

cantdutchthis
  • 31,949
  • 17
  • 74
  • 114
0

If you are trying to access your location via a javascript client, then the geo location API available with HTML 5 is very very helpful.

if(navigator.geolocation){             
    navigator.geolocation.getCurrentPosition(geoLocationSuccess, geoLocationError);
}

geoLocationSuccess and geoLocationError are the callbacks for success and error, respectively.

function geoLocationSuccess(position){
    alert('lat: ' + position.coords.latitude + ', lon: ' + position.coords.longitude);
}
rand_mem_RAM
  • 586
  • 5
  • 6
  • 1
    In this case the user has to give permission through with an alert on the browser which isn't always good as they may not trust the site or bounce – GAV Jul 29 '15 at 11:32