【问题标题】:How to read current location in html5 application如何在 html5 应用程序中读取当前位置
【发布时间】:2016-10-27 20:24:00
【问题描述】:

ASP.NET MVC4 移动 HTML5 在线应用程序在 Android 和 Apple 手机和平板电脑的 Chrome、Android 和 Safari 浏览器中运行。

应用程序包含 html 按钮

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

应该将当前位置发送到服务器。服务器应在地图中显示位置。

如何在 HTML5/Javascript 中实现这一点?据我所知,html5 没有这种可能性。 如果有帮助,我可以强制用户在所有设备上使用 Google Chrome 浏览器。

【问题讨论】:

    标签: javascript android asp.net html google-chrome


    【解决方案1】:

    您可以通过javascript请求职位。

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

    要通过表单发送坐标,您可以使用一些隐藏的输入字段。

    您只能通过 https 请求 chrome >= 50.0 中的位置。

    W3Schools HTML5 Geolocation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多