admin管理员组文章数量:1357273
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
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
Share Improve this question edited Feb 24, 2015 at 15:15 dfsq 193k26 gold badges242 silver badges259 bronze badges asked Mar 31, 2012 at 19:39 Phillip SeamanPhillip Seaman 311 silver badge3 bronze badges 2- If your app goes to the background, your app will be paused and setInterval will not be working, unless you've added in a plugin to keep threads running while the app is in the background. Note that even then there are hard timeouts on how long it will run, as well as possibly breaking app store policies. – tremor Commented Jun 15, 2015 at 15:41
- Is there an alternative that can be used to replicate the functionality of setInterval? – Marty.H Commented Aug 11, 2015 at 16:10
1 Answer
Reset to default 10The way you use setInterval is incorrect. You should pass the reference to the function like this:
setInterval(GetCurrentPosition, 3000);
本文标签: javascriptPhoneGapsetInterval() fails to executeStack Overflow
版权声明:本文标题:javascript - PhoneGap - setInterval() fails to execute - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744038525a2580230.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论