I've successfully used the Android requestLocationUpdates() with the minTime and the minDistance parameters. I'm trying to understand the impact of minDistance on battery usage.
If minDistance is used, is the geolocation (e.g. GPS) continuously being polled to see if minDistance is exceeded?
The Android docs say:
The minDistance parameter can also be used to control the frequency of
location updates. If it is greater than 0 then the location provider
will only send your application an update when the location has
changed by at least minDistance meters, AND at least minTime
milliseconds have passed. However it is more difficult for location
providers to save power using the minDistance parameter, so minTime
should be the primary tool to conserving battery life.
How can the minDistance parameter be used unless the user's geolocation is continuously being polled? It seems like the Android service cannot perform any power-conserving optimization using this parameter.
It's a question of quality. If you only request updates after 100 meters, your gps does not need to run with full resolution. Depending on the driver and supplier, that might save energy. Android offeres a possibility. Whether it is used depends on the gps supplier and the app developer.
Related
I am developing a location based application in which i want to get location after movement of meter from previous position. I don't want to give minimum time in
void requestLocationUpdates (String provider,
long minTime,
float minDistance,
LocationListener listener)
Is there any way to request location updates based only upon minimum distance?
Here is all the information I could find (requestLocationUpdates) :
The minDistance parameter can also be used to control the frequency of
location updates. If it is greater than 0 then the location provider
will only send your application an update when the location has
changed by at least minDistance meters, AND at least minTime
milliseconds have passed. However it is more difficult for location
providers to save power using the minDistance parameter, so minTime
should be the primary tool to conserving battery life.
locationManager.requestLocationUpdates(provider, 2500, 2, this);
You need to walk 2 meters in every 2.5seconds to request for new location?. Correct me if i am wrong. Thank you.
minTime – Wise choice of value for minTime will help you reduce
power consumption. What you need to keep in mind is that elapsed
time between location updates will never be less than minTime, but
it can be greater, because it is influenced by the implementation of
each given Provider and the update interval requested by other
running applications.
minDistance – Unlike minTime this parameter can be turned off by
setting it’s value to 0. However, if minDistance is set to a value
greater than 0, location provider will only send updates to your
application if location has changed at least by given distance. This
parameter is not a great power saver like minTime, but it should be
kept in mind although.
These two parameters work in AND relation, so in order to receive location update, both of their conditions need to be achieved (i.e. more then 5 seconds has passed, and the distance change is greater than 10 meters).
You can check this link:
https://blog.codecentric.de/en/2014/05/android-gps-positioning-location-strategies/
In my application, I have calculated speed based on GPS locations.
As GPS receiver can have different coordinates even being on the same location, my app is recording speed even when phone is on my desk.
I need to avoid GPS data if I am receiving it being on same location.
I am thinking of adding some logic based on “bearing”, so that I can decide if the phone is actually moving or it’s receiving jumpy location data from any direction.
Before that I would like to know is there any other way to avoid this kind of data?
AS per the Javadoc for the method request public void requestLocationUpdates (long minTime, float minDistance, Criteria criteria, PendingIntent intent) found here
minTime minimum time interval between location updates, in
milliseconds minDistance
minimum distance between location updates, in
meters
so you can use minDistance parameter to avoid getting update for very short distances...
After working on many methods I programmed it with bearing.
I am getting speed based on last 5 locations. I added Logic to check bearing for each location with next location and if all bearing have larger difference, I assumed locations are being received from random directions and so the device is not actually moving.
And it worked great for me :)
Porting our location based game to Android.
We rely on updating user location when the app is in the background. What's the best way to accomplish this on the Android side while mitigating battery impact?
We don't need high-frequency updates, even 20 minute cadence is acceptable.
Thanks for any help
You will need to create a Background Service in order to accomplish what you want.
Inside that Background Service you will need to use LocationManager and request for Location Updates.
The function that request for Location Updates takes parameters for the fixes intervals as shown below:
public void requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener)
you will use the minTime parameter to choose the interval between the fixes:
minTime : the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value.
LocationManager#requestLocationUpdates allows you to pass in a minTime and minDistance parameter. I'm having a hard time deciding what these numbers should be, and could appreciate some guidance.
Our app is not a turn-by-turn navigation app; I just want to show the 10 nearest points of interest. Since I'm showing the 10 nearest, they can get a little stale, but if the user is in a moving vehicle, I'd want/need to update them pretty frequently to avoid staleness.
I imagine a lot of people are in the same position of vague requirements: "I don't want the data to be too stale, but I don't want to waste battery." How can I turn these vague requirements into concrete numbers?
***<Edit>***
As of JellyBean, the criteria is (minTime & minDistance), so it has
to satisfy both to return a location.
***</Edit>***
Based on your problem, it sounds to me like the minTime parameter is irrelevant.
What you really need to worry about is minDistance, so that if a user is in a fast moving vehicle, it will keep up.
If a person is driving 60 MPH, they move about 27 meters per second.
Considering this critera... I would say to use:
minTime = 60000 // update every 60 seconds
minDistance = 90 // in a fast moving vehicle, it will update roughly once every 3 seconds
It has been described nicely in requestLocationUpdates docs
The frequency of notification or new
locations may be controlled using the
minTime and minDistance parameters. If
minTime is greater than 0, the
LocationManager could potentially rest
for minTime milliseconds between
location updates to conserve power. If
minDistance is greater than 0, a
location will only be broadcast if the
device moves by minDistance meters. To
obtain notifications as frequently as
possible, set both parameters to 0.
Background services should be careful
about setting a sufficiently high
minTime so that the device doesn't
consume too much power by keeping the
GPS or wireless radios on all the
time. In particular, values under
60000ms are not recommended.
I can suggest a better idea that, initially request updates with a little larger interval and get the locations. Now check if the distance between the consecutive locations is more than the minimum distance to distinguish the nearer locations, change your request update interval to lower value. Similarly if in this lower interval the distance you computed of much lower that indicates the user in not traveling through vehicle then update interval to larger value.
To update the interval you have to unregister previous listener and then re-regiser with new value.
For your problem at hand, do take a look at the PASSIVE_PROVIDER. Basically it will help you get updates when any other apps might request for them. So, you can use this in conjunction with other provider.