oud*_*ken 5 geolocation ios cordova
平台:iOS6/OSx Lion.
我试图解开Phonegap/Cordova的工作方式navigator.geolocation.watchPosition.
文档说选项" maximumAge"是要求系统检索位置的选项.
所以有这些选择:
{ maximumAge: 3000, timeout: 5000, enableHighAccuracy: true }
Run Code Online (Sandbox Code Playgroud)
我认为位置请求会每3秒触发一次?
而且不管maximumAge我说什么,成功每1秒钟就会被解雇......
有人可以解释一下吗?
谢谢Bye
Rob
我目前正在使用getCurrentPositiona 来解决这个问题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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5468 次 |
| 最近记录: |