I am trying to build a PhoneGap app that updates the Location every few seconds. I have tired to impliment the setInterval() function. But it fails to run!
My code segment looks like this...
// Set time interval and keep excuting every 3 secs
var i = 0;
setInterval(GetCurrentPosition(), 3000); // this will call GetCurrentPosition() each 3 sec
function GetCurrentPosition() {
// retrieve your info here
console.log('i = ' + z i);
i = i + 1;
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
As you can see I added a counter to see if it is firing... it only fires when I call it manually.
Anyone got any suggestions to what I am doing wrong or need to add to correct my error?
Thanks
The way you use setInterval is incorrect. You should pass the reference to the function like this:
setInterval(GetCurrentPosition, 3000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With