Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improving Android GPS performance

Tags:

java

android

gps

How do you improve slow GPS signal acquisition on the Android platform?

I'm testing a simple GPS logger based on this open source code, and although it seems to work, it can take up to 10-15 minutes for it to first acquire a signal and start showing GPS coordinates. However, running the Google Maps app on the same device appears to acquire a signal almost instantly (it's even able to detect which direction I'm facing in realtime), while the GPS logger service still says it can't find a signal.

Why is Google Maps so fast at acquiring a GPS signal, while the standard GPS system service takes forever?

The specific code I have that starts the GPS service is:

private void startLoggerService() {
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    locationListener = new MyLocationListener();
    lm.requestLocationUpdates(
        LocationManager.GPS_PROVIDER, 
        2000, 
        1,
        locationListener);
}
like image 500
Cerin Avatar asked Nov 29 '25 10:11

Cerin


1 Answers

There are a couple of things you should be aware of and definitely take into consideration when it comes to using positional data:

  • Don't rely on just the GPS sensor. Although GPS can potentially give you the most accurate result, it is relatively slow and quite the battery hog. In stead, also request location updates from the network provider: LocationManager.NETWORK_PROVIDER. In most cases this will give a result accurate enough to use in your app (most devices I've played with seem to yield a worst case accuracy of roughly 60~65m), but more importantly: it's much, much faster. Do note that just as with the GPS, users can enable and disable feature themselves in the system settings. For more details, see Using the Location Manager.
  • Think about how often you need a location update. If possible, prevent continuous updates (that'll drain the battery in no-time) and release the sensors as soon as you've received the data you require. Also, a good practice is to cache the location to some extend - even if it's not completely accurate, users do get feedback immediately. You can potentially combine this with some logic that takes the time stamp into account.
  • Use the resources that are already available on the Android Developer website. For example, there is a topic on Location Strategies that will be worth reading. Another good resource will be the blog post by Reto Meier and his open source project that implements his Android Protips for Location. If you have the time, also go over his Google I/O 2011 presentation that discusses best-practices for location-based/location-aware Android apps.

On a side note: the realtime indication of what direction you're facing has nothing to do with locations, but comes from either the magnetic field sensor (read: digital compass) or gyroscope. Both deal with the device's orientation, not position.

like image 79
MH. Avatar answered Dec 02 '25 01:12

MH.