开发者

How to convert IP Address to GeoLocation using ASP.Net or Razor Systax or Bing Map?

开发者 https://www.devze.com 2023-02-07 04:44 出处:网络
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:/

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消