Phonegap geolocation is slow on Android

Whilst developing a geolocation based app for android using Cordova 3.3, I found that the geolocated position was not updated very fast.

Turns out that there is a setting in the geolocation plugin java files that control the minimum time that phonegap / Cordova will check for changes.

This is regardless of wether I use watchPosition or getCurrentPosition.

If I want it to check at least every 5 seconds, I can change the files as follows:

GeoBroker.java

Change line 75

from:

this.getCurrentLocation(callbackContext, enableHighAccuracy, args.optInt(2, 60000));

to:

this.getCurrentLocation(callbackContext, enableHighAccuracy, args.optInt(2, 5000));

GPSListener.java

Change line 44

from:

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

to:

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

Then remake your project.

Worked fine for me and the Nexus 7 (2013) is updating my map every second or two.

Hope this helps someone.

Mark

Share

Leave a comment