在 .Net Core Web 应用程序中获取移动地理位置 [英] Get mobile GeoLocation in .Net Core web app

查看:21
本文介绍了在 .Net Core Web 应用程序中获取移动地理位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个可以在手机上运行的 .Net Core Web 应用程序.此应用程序需要检测移动地理位置以跟踪用户位置.

I want to develop a .Net Core web app that will run on mobile phones. This app needs to detect the mobile geo location for tracking the user location.

这个应用程序的服务器端和客户端都应该运行在手机上;即服务器端只是应用程序中的一个逻辑层,而不是一个单独的应用程序.由于这应该是一个小应用程序,我想消除维护单独服务器的需要并为此使用客户端资源,因此用户需要的只是一个无需连接到服务器的移动应用程序.

Both server and client sides of this app should run on the mobile phone; i.e. the server side is just a logic layer in the app, not a separate app. Since this should be a tiny app, I want to remove the need of maintaining a separate server and use the client resources for that, so all what the user needs is a mobile app without connecting to a server.

我知道.Net Core 中目前没有GPS API 支持,所以我想使用一些网络服务来实现这一点.

I understood that there is no currently GPS API support in .Net Core, so I thought to consume some web service for doing that.

我用谷歌搜索了很多,但找不到我可以使用的网络服务(没有添加必须安装在移动设备上的罕见依赖项).

I googled a lot but couldn't find such web service that I can use (without adding uncommon dependency that will have to be installed on the mobile as well).

这样的做法好吗?或者有更好的解决方案?如果是 - 我可以使用什么网络服务?

Is this way a good practice? or there is a better solution? If it is- what web service can I use?

推荐答案

.NET Core Web 应用程序在服务器端运行 - 手机是您的 Web 应用程序的客户端,并且很可能会在浏览器中显示 HTML 结果.因此,要检测您将使用的地理位置,例如JavaScript 和 HTML5 GeoLocation API.

The .NET Core Web Application runs on the server side - the mobile phone is the client of your webapplication and will likley display the HTML result in the browsers. So to detect the GeoLocation you will use e.g. JavaScript and the HTML5 GeoLocation API.

<script>
 function getLocation() {
   if (navigator.geolocation) {
     navigator.geolocation.getCurrentPosition(showPos);
   } else {
     alert("Geolocation is not supported by browser");
   }
 }

 function showPos(position) {
   alert("Lat: " + position.coords.latitude +  " Long: " + position.coords.longitude); 
 }
</script>

这篇关于在 .Net Core Web 应用程序中获取移动地理位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆