This is the way I listen for GPS location updates (using LocationManager
and a LocationListener
):
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
listener = new MyLocationistener(); // LocationListener
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
30000, // milliseconds (minTime)
20, // meters (minDistance)
listener );
But I would like to dynamically adjust the minTime
and minDistance
arguments used by LocationManager#requestLocationUpdates
. My aim is to save battery, according to several usage policies, i.e.:
- If the user is not moving, increase the minTime to get a location update
- If the user is moving very fast, increase the minDistance
- If the user is indoors (no GPS coverage), increase both
- If the battery is too low, increase both
- ... (any other heuristic)
I would like to know:
- Is this really a good idea to save battery life ?
- How could I do that kind of adjustments? I can call both
LocationManager#removeUpdates
andLocationManager#requestLocationUpdates
again, if there is the only alternative. - Any idea or sample code you know to implement this kind of adaptive algorithms ?
Edit: The application is a tracking system to know where people are, in order to assign tasks to the person nearest to a given poing. Actually battery hardly lasts 8 hours, so I'd like to increase it.