【问题标题】:The cordova navigator.geolocation.getCurrentPosition api always return error code 3cordova navigator.geolocation.getCurrentPosition api 总是返回错误代码 3
【发布时间】:2014-07-16 14:42:01
【问题描述】:

当我使用 worklight 开发标准混合应用程序时,我使用以下示例代码,但我无法获取设备上的位置信息,即使我在街上。它总是返回错误代码3。它可以成功多次。你能帮助如何使它工作吗?我在 Worklight 6.1 和 6.2 上进行测试,同样的问题。

我在 Android 设备三星 S3 上进行测试。

谢谢。

var onSuccess = function(position) {
    alert('Latitude: '          + position.coords.latitude          + '\n' +
          'Longitude: '         + position.coords.longitude         + '\n' +
          'Altitude: '          + position.coords.altitude          + '\n' +
          'Accuracy: '          + position.coords.accuracy          + '\n' +
          'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
          'Heading: '           + position.coords.heading           + '\n' +
          'Speed: '             + position.coords.speed             + '\n' +
          'Timestamp: '         + position.timestamp                + '\n');
};

// onError Callback receives a PositionError object
//
function onError(error) {
    alert('code: '    + error.code    + '\n' +
          'message: ' + error.message + '\n');
}

navigator.geolocation.getCurrentPosition(onSuccess, onError);

【问题讨论】:

  • 试试这个代码,让我知道。 navigator.geolocation.getCurrentPosition(onSuccess, onError, { enableHighAccuracy: true, timeout: 30000, maximumAge: 30000 });

标签: cordova geolocation ibm-mobilefirst


【解决方案1】:

PositionError 代码 3 用于超时。您可能想尝试 Bluewings 的建议。另请注意,您可以尝试改用 WL.Device.Geo.acquirePosition API。

【讨论】:

    【解决方案2】:

    代码 3 - 超时。

    设置更长的超时时间:

    navigator.geolocation.getCurrentPosition(
        onSuccess, 
        onError, 
        {
            **timeout: 10000**, 
            maximumAge: Infinity
        };
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-04
      • 1970-01-01
      • 2014-10-11
      • 1970-01-01
      相关资源
      最近更新 更多