user1014759
user1014759

Reputation: 265

Returning inaccurate GPS coordinate using getCurrentPosition in Phonegap

I am developing a PhoneGap application with JQuery mobile which requires geolocation data. Currently the positions returned by getCurrentPosition() are very inaccurate, sometimes up to a mile away. It appears that the application is using googles location services to acquire the positions. Is there any way to force the application to use the GPS?

Also the first time a position is posted it often returns an old position (even though maximumAge is set to 0). Does anyone know why this could be?

I have read through the geolocation API below and have no been able to find anything.

http://dev.w3.org/geo/api/spec-source.html

Upvotes: 1

Views: 4606

Answers (3)

Kim Ras
Kim Ras

Reputation: 41

As the other writes. the getCurrentPosition is not necessarily accurate to the meter, it all depends of the GPS is active or not..

The getCurrentPossition is meant for a quick get of position for searches and initial position while the GPS get propper fix..

I normally do this:

//Initialize GPS
navigator.geolocation.getCurrentPosition(onGPSSuccess, onGPSError, { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true }); 
navigator.geolocation.watchPosition(onGPSSuccess, onGPSError, { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true }); 

Thant will get a quick posting and the the watch function will repeatedly get called for the position..

So if you expect a accurate coordinate you could check the : position.coords.accuracy for the accuracy in meters in the call back function.

Upvotes: 2

Martin Zeitler
Martin Zeitler

Reputation: 76849

This is Geolocation API, not a hardware GPS fix - so you might only get the network location. Some stock browser also have a proximity "feature"... for example, with Fennec it works fine.

Upvotes: 0

Simon MacDonald
Simon MacDonald

Reputation: 23273

A couple of things you can try is to make sure you are setting the enableHighAccuracy parameter to true in your call to getCurrentPosition.

However, most GPS chips need a bit of time before it gets you an accurate position. The better solution is to call watchPosition and wait until you get 3 to 5 results as you will find the accuracy is much better in this case. Then you can do a clearWatch and use the more accurate GPS position.

Upvotes: 5

Related Questions