1

I'm using a LocationClient to get the current location every minute:

mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(60000);
mLocationRequest.setFastestInterval(60000);
mLocationClient = new LocationClient(this, this, this);
// ... when connected:
mLocationClient.requestLocationUpdates(mLocationRequest, this);

However I noticed that my LocationListener's onLocationChanged-method is called either every 60 or 120 (or any other multiple of 60) seconds (+/- 3 seconds). The documentation says:

This interval is inexact. You may not receive updates at all (if no location sources are available), or you may receive them slower than requested. [...]

So I know, that the interval is not exact one minute. But I thought that I would get the current location as fast as possible after the 60 seconds are over, for example after 75 seconds. But it seems that if the LocationClient cannot determine the location it simply retries after the next 60 seconds.

Is this assumption correct?

If yes, a workaround would be to set the interval to something lower like 30 seconds or so and filter out the required locations in the onLocationChanged-method. But that would probably consume more battery power.

Biggie
  • 7,037
  • 10
  • 33
  • 42

1 Answers1

2

When you call mLocationRequest.setFastestInterval(60000); you are saying that you cannot handle more than one call every 60 seconds, hence why it is waiting on 60 second intervals before sending you an update (even if it gets it 45 seconds before the next 60 second period) - lower the setFastestInterval to ensure that location updates are sent to you quickly after receiving them. As the actual polling frequency is tied to setInterval (and not the fastest interval) increasing your setFastestInterval should not increase battery usage.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • But lowering the setFastInterval can cause my onLocationChanged-method to be called more often than every 60 seconds which is not what I want. ;-) I want something like: Call my onLocationChanged-method only once every 60 seconds but if you doesn't have a location after 60 seconds, then call my method as soon as possible as you get the next coordinate. – Biggie Jan 23 '14 at 19:44
  • 1
    Today I made the test: Lowering the FastInterval results in a more stable 60-sec interval of location updates. However if running for example the "My tracks"-app in the background with a very small interval causes my app's LocationListener to be called at its FastInterval-rate (like expected). So I have to filter again the needed locations to get my 60-sec interval. So the workaround still seems to be setting the Interval/FastInterval to something lower than the wanted interval (which was my suggestion above). – Biggie Jan 24 '14 at 12:26