【问题标题】:Can not get GPS from Google Chrome in Android无法从 Android 中的 Google Chrome 获取 GPS
【发布时间】:2016-09-06 14:21:54
【问题描述】:

我有一些用于从浏览器获取 GPS 的 javascript 代码。 它可以在:Chrome (Window 7-PC)、Firefox (Window 7-PC)、Firefox (Android 5.0-Smartphone) 中获得精确的 GPS。 但是使用 Chrome (Android 5.0-Smartphone) 无法获取 GPS。 我的代码:

function getLocation() {
if (navigator && navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(successGPS, errorGPS, {enableHighAccuracy: true, timeout: 60000});
} else {
    console.log('Geolocation is not supported');}}

function successGPS(position) {
latLng_taxi = new google.maps.LatLng(position.coords.latitude,
        position.coords.longitude);
alert(latLng_taxi);}

function errorGPS() {
alert("Cant get GPS");}

请告诉我我的问题以及如何使用 Chrome (Android) 获取 GPS

【问题讨论】:

    标签: google-maps google-chrome gps android-gps


    【解决方案1】:

    您可以尝试查看HTML5 Geolocation,如果它可以帮助您。

    此 API 不仅在 Google Chrome 中受支持,在 IE、Mozilla、Safari 和 Opera 中也受支持,但请注意,它具有支持此功能的特定浏览器版本。

    本文档还为您提供了有关如何实现此目的的示例代码,包括处理错误和拒绝、在地图中显示结果、地理定位对象 - 其他有趣的方法等。只需阅读文档链接以了解有关此 API 的更多信息。

    有关更多信息,请查看此SO question 和此link

    【讨论】:

      【解决方案2】:

      因为我的手机使用 Chrome(52.0),所以它需要 https 协议来获取 GPS。

      1. 我的主机(在桌面上)使用 http -> 我的手机无法获取 GPS。
      2. 在桌面上我使用 Chrome (53.0) 但它可以获取 GPS,因为 Chrome 运行在我的 本地主机

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-09-24
        • 2017-09-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多