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#removeUpdatesandLocationManager#requestLocationUpdatesagain, 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.
AFAIK you need to call
removeUpdatesandrequestLocationUpdatesagain.Also, you can look into other ways to see if the phone is moving at all, like the accelerometer. Read about it here and see this other question’s answers
But To give you more ideas, you need to present the problem itself. Don’t try to optimize too early, until you don’t have a problem. If you have you need to post details about it.