Pitbi
Pitbi

Reputation: 83

PhoneGap 3.3 : how to have the best accuracy?

I make an application with PhoneGap and I need the best geolocation possible.

I use this:

var options = { enableHighAccuracy: true, timeout:30000};
navigator.geolocation.getCurrentPosition(success, fail, options);

I tried to refine the search with:

var options = { enableHighAccuracy: true, timeout:30000};
navigator.geolocation.watchPosition(success, fail, options)

But it return approximately same accuracy (between 10 and 40 in several type of place).

Also, geolocation functions (getCurrentPosition and watchPosition) are very slow. Often the timeout is exceeded (30s).

I did a lot of research on the web, but I found nothing that could help me. Could you help me? Are there a good way to have the best geolocation? Is it possible with PhoneGap, make a loop to receive every second gps data?

Thank you in advance.

Regards.

Upvotes: 2

Views: 382

Answers (1)

Pitbi
Pitbi

Reputation: 83

Ok, I found the solution...

In the file app/platforms/android/src/org/apache/cordova/geolocation/GPSListener.java :

I change:

this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, this);

by

this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 0, this);

Like that, I receive GPS datas much faster. I do

watchID = navigator.geolocation.watchPosition(geolocalizeWatchSuccess, geolocalizeWatchError, { timeout: 20000 , enableHighAccuracy: true, maximumAge: 30000});

And i catch the best possible accuracy.

Apparently this problem comes from phonegap 3.x.

Bye.

Upvotes: 1

Related Questions