How can I find a user's GEO Location using ASP.NET?

自作多情 提交于 2019-11-30 18:45:39

问题


How can I get hold of a user's GEO location within my ASP.NET application? I've noticed on browsers like Firefox and Google Chrome, I (as the user) am prompted as to whether or not to allow the site to have access to my location.

How can I achieve a similar thing to this?


回答1:


The prompt you're seeing is shown when a site uses the Geolocation API. It's all JavaScript, so you don't need any kind of server support to use it. If you want the values on the server side, you can send them back using XMLHttpRequest or a simple form post.

Here's a demo with easy to read source code as well.




回答2:


Use the regular HTML5 Geolocation tools to get the location and then use AJAX to send the location back to your ASP.NET Server Side code and update whatever client elements are necessary.



来源:https://stackoverflow.com/questions/3753022/how-can-i-find-a-users-geo-location-using-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!