Phonegap geolocation.watchPosition does not update location on iPhone

I am developing a phonegap app that sends the current GPS location to a server. For this we have the following piece of code:

navigator.geolocation.watchPosition(gpsTracker.onNewCoordinates, gpsTracker.onError, {
    enableHighAccuracy : true,
    maximumAge: 4000, //should be default, just in case
    timeout: 5000
});

      

The callback functions will take care of the presentation of the results. This feature works very well on our test Android device. However, when we run the same code on an iOS device, it usually does nothing, except when GPS reception is ok, it will send two coordinates and then stop.

It looks like iOS only gets some information once and never triggers callback functions when new coordinates are available.

Anyone with a similar experience / solution to this problem?

+3


source to share


2 answers


I solved my problem as follows. It turns out that navigator.geolocation.watchPosition

doesn't seem to work on iOS. I rewrote the code with javascript setInterval

that calls 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 returns correctly every 5 seconds.

+3


source


Have a look at this: http://groups.google.com/group/phonegap/browse_thread/thread/58f7ff98170b16c4 There is something written about geolocator.start () and stop () kept for iOS. Maybe this helps?



In my experience, GPS needs to be "hot" to deliver valid positions ie. he needs to be given enough time to connect to satellites, etc. Usually you only have a "hot" one if you start watching, not if you just select individual positions. Therefore, on my HTC, the values ​​obtained by the getCurrentPositions () method turned out to be too fuzzy (related to the near field of view, for example, within 50 m). So this might be the right way to try again with the startWatching () function.

0


source







All Articles