12-09-2018 09:50
12-09-2018 09:50
I am writing a app with using the geolocation interface. I can build and run the app without errors. But after 2-3 minutes run this app my Ionic fails and restart. Anyone have an idea what is wrong in my script?
-------------------------------------------------------------------
Answered! Go to the Best Answer.
12-11-2018 15:32
12-11-2018 15:32
You're probably flooding requests to getPosition() because you aren't waiting for success.
You should probably either switch over to watchPosition(), or stop using setInterval(), and use setTimeout() after location success. Something like:
function getPosition() { geolocation.getCurrentPosition(locationSuccess, locationError, locationOptions); console.log("start loop getCurrentPosition"); } function locationSuccess(position) { // ... setTimeout(getPosition, 5000); } // Start getting position getPosition();
12-11-2018 15:32
12-11-2018 15:32
You're probably flooding requests to getPosition() because you aren't waiting for success.
You should probably either switch over to watchPosition(), or stop using setInterval(), and use setTimeout() after location success. Something like:
function getPosition() { geolocation.getCurrentPosition(locationSuccess, locationError, locationOptions); console.log("start loop getCurrentPosition"); } function locationSuccess(position) { // ... setTimeout(getPosition, 5000); } // Start getting position getPosition();