ios - Phonegap、Cordova 观察位置每 1 秒成功发射一次

标签 ios cordova geolocation

平台:iOS6/OSx Lion。

我正在尝试弄清楚 Phonegap/Cordova 与 navigator.geolocation.watchPosition 的工作方式。

文档说选项“maximumAge”是要求系统检索位置的选项。

因此,使用这些选项:

{ maximumAge: 3000, timeout: 5000, enableHighAccuracy: true }

我预计职位请求将每 3 秒触发一次?

无论 maximumAge 我把成功每 1 秒触发一次......

谁能解释一下吗?

谢谢再见
罗布

最佳答案

我目前正在通过将 getCurrentPositionsetInterval 结合使用来解决此问题。我不确定会产生什么后果,但这似乎给了我最大的控制权,并且似乎是跨平台最一致的方法。

// call this once
setupWatch(3000);

// sets up the interval at the specified frequency
function setupWatch(freq) {
    // global var here so it can be cleared on logout (or whenever).
    activeWatch = setInterval(watchLocation, freq);
}

// this is what gets called on the interval.
function watchLocation() {
    var gcp = navigator.geolocation.getCurrentPosition(
            updateUserLoc, onLocationError, {
                enableHighAccuracy: true
            });


    // console.log(gcp);

}

// do something with the results

function updateUserLoc(position) {


var location = {
    lat : position.coords.latitude,
    lng : position.coords.longitude
};

console.log(location.lat);
console.log(location.lng);
}

// stop watching

function logout() {
    clearInterval(activeWatch);
}

关于ios - Phonegap、Cordova 观察位置每 1 秒成功发射一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13254420/

相关文章:

android - Cordova 和使用命令行设置 Android

ios - 在没有首选项的情况下在 iOS 中获取 iPhone 位置 位置服务设置为 ON

mongodb - Mongodb 复合索引与地理定位不起作用

android - 位置总是返回 null - android

ios - iPhone MKMapView - MKPolygon 问题

ios - 由于未捕获的异常 'NSInvalidArgumentException' 而终止应用程序,原因 : '-[NSNull _fastCStringContents:]: unrecognized selector

iOS 11.3 ARKit 自动对焦和更高分辨率

ios - 无法让平移手势工作

javascript - 适用于 Windows Phone 的 Cordova Visual Studio 2012 Express : Open External PDF URL

ios - ionic 应用程序恢复和暂停