简体   繁体   English

如何在HTML5应用程序中读取当前位置

[英]How to read current location in html5 application

ASP.NET MVC4 mobile HTML5 online application is running in Android and Apple mobiles and tablets in Chrome, Android and Safari browsers. ASP.NET MVC4移动HTML5在线应用程序在Android,Apple手机和平板电脑的Chrome,Android和Safari浏览器中运行。

Application contains html button 应用程序包含html按钮

<form action='SavePosition'>
  <input type='submit' value='Send' name='position'>
  </form>

which should send current location to server. 它将当前位置发送到服务器。 Server should display locations in map. 服务器应在地图上显示位置。

How to implement this in HTML5/Javascript ? 如何在HTML5 / Javascript中实现呢? Based on my knowledge html5 does not have such possibility. 根据我的了解,html5没有这种可能性。 I can force users to use Google Chrome browser in all devices if this helps. 如果有帮助,我可以强迫用户在所有设备上使用Google Chrome浏览器。

You can request the position via javascript. 您可以通过javascript请求该职位。

if (navigator.geolocation)
    navigator.geolocation.getCurrentPosition(function(position) {
        console.log("latitude: " + position.coords.latitude);
        console.log("altitude: " + position.coords.altitude);
    })

To send the coords via the form you could use some hidden input fields. 要通过表格发送坐标,您可以使用一些隐藏的输入字段。

You can only request the position in chrome >= 50.0 only via https. 您只能通过https请求chrome> = 50.0中的位置。

see W3Schools HTML5 Geolocation 请参阅W3Schools HTML5地理位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM