Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap, Cordova watchposition fire success every 1 second

Platform: iOS6/OSx Lion.

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

The docs says that the option "maximumAge" is the one that ask the system for retrieve the position.

So with these options:

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

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

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

Anyone can explain please?

Thanks Bye
Rob

like image 629
oudoken Avatar asked Nov 06 '12 15:11

oudoken


People also ask

What is the difference between PhoneGap vs Cordova?

Let us discuss some key differences between PhoneGap vs Cordova in the following points: 1. PhoneGap is Adobe Systems ‘ cross-platform mobile development system to build mobile platform-independent applications. It is using standard web technologies such as JavaScript, HTML, and CSS to connect web apps to mobile devices. 2.

What is PhoneGap?

PhoneGap originally started as an open-source project by Nitobi Software in 2008. Nitobi Software was acquired by Adobe in 2011 and shortly after donated PhoneGap to the Apache Software Foundation as Cordova.

What happened to Apache Cordova?

Apache Cordova, which was a core tool of Adobe PhoneGap and PhoneGap Build for the past nine years, will continue to thrive as long as the health of the community remains strong and contributions are made. If you use, have used, or looking to start using Cordova, also consider contributing and taking part in this awesome community to help it grow.

Can I use PhoneGap and Cordova with IntelliJ IDEA?

The plugin is available only in IntelliJ IDEA Ultimate. PhoneGap and Apache Cordova are frameworks for developing mobile application with single HTML, CSS, and JavaScript/TypeScript code base and targeting various mobile platforms, including Android.


1 Answers

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);
}
like image 92
scald Avatar answered Sep 28 '22 05:09

scald