Phonegap,Cordova监视位置每1秒发射一次成功 [英] Phonegap, Cordova watchposition fire success every 1 second

查看:52
本文介绍了Phonegap,Cordova监视位置每1秒发射一次成功的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

平台:iOS6 / OSx Lion。

Platform: iOS6/OSx Lion.

我想弄清楚Phonegap / Cordova与 navigator.geolocation.watchPosition的工作方式

I'm trying to puzzle out the way Phonegap/Cordova work with navigator.geolocation.watchPosition.

文档说,选项 maximumAge 是要求

因此,使用以下选项:

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

我认为该职位请求将会每3秒钟触发一次?

I espect the position request will be fired every 3 seconds?

无论我把什么 maximumAge 都每1秒触发一次...

And no matter what maximumAge I put the success is fired every 1 second...

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

Anyone can explain please?

感谢再见

抢劫

Thanks Bye
Rob

推荐答案

我目前正在通过将 getCurrentPosition setInterval 。我不确定会带来什么后果,但这似乎使我拥有最大的控制权,并且似乎是跨平台的最一致的方法。

I am currently working around this issue by using getCurrentPosition with a setInterval. I'm not sure what the consequences may be, but this seems to give me the most control and appears to be the most consistent method across platforms.

// 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);
}

这篇关于Phonegap,Cordova监视位置每1秒发射一次成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆