【问题标题】:GPS Geolocation app doesn't work in Phonegap for AndroidGPS 地理定位应用程序在 Android 的 Phonegap 中不起作用
【发布时间】:2013-01-14 19:14:21
【问题描述】:

我正在创建一个获取用户位置的应用程序。这些应用程序使用 3G 可以正常工作,当我禁用 3G 并想仅使用 GPS 运行应用程序时,问题就出现了,该应用程序甚至无法启动。

我的代码:

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    navigator.geolocation.getCurrentPosition(onSuccess, onError);
}

function onSuccess(position) {
    var element = document.getElementById('geolocation');
    element.innerHTML = 'Latitude: '           + position.coords.latitude              + '<br />' +
                        'Longitude: '          + position.coords.longitude             + '<br />' +
                        'Altitude: '           + position.coords.altitude              + '<br />' +
                        'Accuracy: '           + position.coords.accuracy              + '<br />' +
                        'Altitude Accuracy: '  + position.coords.altitudeAccuracy      + '<br />' +
                        'Heading: '            + position.coords.heading               + '<br />' +
                        'Speed: '              + position.coords.speed                 + '<br />' +
                        'Timestamp: '          + new Date(position.timestamp)          + '<br />';
}

function onError(error) {
    alert('code: '    + error.code    + '\n' +
          'message: ' + error.message + '\n');
} 

【问题讨论】:

标签: android cordova geolocation


【解决方案1】:

地理位置并不意味着您将使用 GPS。默认情况下,您将使用网络位置。您必须启用高精度!

【讨论】:

  • 这是通过将 Position.FINE 添加到清单中的权限来完成的,根据我在下面的回答。
【解决方案2】:

确保您在清单中的权限包括 Position.FINE,以便您的应用程序可以使用 gps 接收器。

【讨论】:

    【解决方案3】:

    转到您的 Android Manifest 并检查您是否有权执行此操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-06
      • 1970-01-01
      相关资源
      最近更新 更多