平台:iOS6/OSx Lion。
我试图弄清楚 Phonegap/Cordova 的工作方式navigator.geolocation.watchPosition
.
文档说该选项“maximumAge
" 是要求系统检索位置的一个。
因此,有了这些选项:
{ maximumAge: 3000, timeout: 5000, enableHighAccuracy: true }
我尊重每 3 秒就会触发一次位置请求?
并且无论怎样maximumAge
我把成功每1秒触发一次......
任何人都可以解释一下吗?
谢谢再见
Rob
我目前正在通过使用解决这个问题getCurrentPosition
with a 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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)