Reputation: 3996
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?
Upvotes: 4
Views: 8120
Reputation: 3710
Have a look at this: http://groups.google.com/group/phonegap/browse_thread/thread/58f7ff98170b16c4 There is something written about geolocator.start() and stop(), preserved for iOS. Maybe this helps?
According to my experience, the GPS must be "hot" in order to deliver valid positions, i.e. it must be given enough time to connect to satellites etc. Usually, you have it "hot" only if you start watching, not if you just pick single positions. On my HTC, values gained by getCurrentPositions() have therefore turned out too unprecise (related to a near scope, e.g. within 50m). So it might be the right way to try once more to find a solution with startWatching().
Upvotes: 0
Reputation: 3996
I solved my issue as follows. It turns out that navigator.geolocation.watchPosition
does not seem to work well on iOS. I rewrote the code using a javascript setInterval
which invokes getCurrentPosition
every 5 seconds instead:
navigator.geolocation.getCurrentPosition( gpsTracker.onNewCoordinates, gpsTracker.onError, {
enableHighAccuracy : true,
maximumAge: 4000, // should be default, just in case
timeout: 5000
});
Now the GPS position is correctly returned every 5 seconds.
Upvotes: 5