I am developing a phonegap application that sends the current GPS location to a server. In order to do so, we have the following code fragment:
navigator.geolocation.watchPosition(gpsTracker.onNewCoordinates, gpsTracker.onError, {
enableHighAccuracy : true,
maximumAge: 4000, //should be default, just in case
timeout: 5000
});
The callback functions take care of submitting the results. On our Android test-device this functionality is working just nicely. However when we run the same code on an iOS device it usually does nothing, except when the GPS reception is fine it will send two coordinates and then it stops.
It looks like iOS only obtains some information once, and never triggers the callback functions when there are new coordinates available.
Anyone with similar experience / solution to this problem?
I solved my issue as follows. It turns out that
navigator.geolocation.watchPositiondoes not seem to work well on iOS. I rewrote the code using a javascriptsetIntervalwhich invokesgetCurrentPositionevery 5 seconds instead:Now the GPS position is correctly returned every 5 seconds.