How to convert IP Address to GeoLocation using ASP.Net or Razor Systax or Bing Map?
I build the ASP.Net (.cshtml) site, and I need to get current location of user to show in Bing Map. How can I 开发者_开发问答do this feature?
MaxMind offers a IP geolocation library and API, see: http://www.maxmind.com/app/api
They offer a number of Windows APIs, including C#. see: http://www.maxmind.com/app/windows
(Disclaimer: not affiliated, just a happy customer. I've not used the Windows APIs).
I wouldn't ever try to implement this myself. Using HTML5 you can actually get the best location available for the computer/device trying to view the page. One of the fallbacks that browsers use when there isn't a GPS device attached it to lookup the location of the IP address. This only works in HTML5 browsers but it's a very fast and cheap solution.
Javascript:
navigator.geolocation.getCurrentPosition(show_map);
function show_map(position) {
var lat = position.coords.latitude;
var lng = position.coords.longitude;
}
If you want more details I find this site really useful.
http://diveintohtml5.ep.io/geolocation.html
did you checked nerddinner tutorial, chapter 11: Integration with an ajax map? http://nerddinnerbook.s3.amazonaws.com/Part11.htm
Nerddinner uses js files -included in the example - plus a location request - included in the example too - .
to download files http://nerddinner.codeplex.com/SourceControl/list/changesets if you want razor´s examples, otherwise http://nerddinner.codeplex.com/ Full tutorial starts here http://nerddinnerbook.s3.amazonaws.com/Intro.htm brgds.
精彩评论