5

平台:iOS6/OSx Lion。

我试图弄清楚 Phonegap/Cordova 使用navigator.geolocation.watchPosition.

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

因此,使用这些选项:

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

我认为位置请求将每 3 秒触发一次?

而且无论maximumAge我放什么,每 1 秒就会触发一次成功...

任何人都可以解释一下吗?

谢谢再见
罗伯

4

1 回答 1

6

我目前正在通过getCurrentPosition使用setInterval. 我不确定后果可能是什么,但这似乎给了我最大的控制权,并且似乎是跨平台最一致的方法。

// 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);
}
于 2012-11-06T17:31:49.473 回答