如何以编程方式在c#中获取当前GPS位置?

时间:2016-08-03 11:30:33

标签: c# gps

我正在研究MVC 5应用程序。

我们说我有GPS设备,我想在我的应用程序中使用GPS位置,我应该使用什么api /代码?

例如,如果我有旅行社,我有2辆汽车,两辆车都有GPS设备,条件是"如果我的GPS启用汽车停止超过2.5分钟在路上,那么我需要一个ping我的Gps设备。"

2 个答案:

答案 0 :(得分:1)

使用MVC 5,您可以选择是在服务器端还是client-side。我建议:

navigator.geolocation.getCurrentPosition(success[, error[, options]])
来自JavaScript的

。然后:

if ("geolocation" in navigator) {
  navigator.geolocation.getCurrentPosition(success, error, options)
} else {
  /* geolocation IS NOT available, maybe use a server side method! */
}

使您的服务器受益,因为他们的工作量也很少。

答案 1 :(得分:0)

您可以使用浏览器功能(Geolocation API)来读取当前位置。

var x = document.getElementById("demo");
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude + 
    "<br>Longitude: " + position.coords.longitude; 
}

http://www.w3schools.com/html/html5_geolocation.asp

相关问题