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.

4

1 回答 1

2

当您打电话时mLocationRequest.setFastestInterval(60000);,您说您每 60 秒不能处理一个以上的电话,因此为什么它在向您发送更新之前等待 60 秒间隔(即使它在下一个 60 秒周期前 45 秒得到它) - 降低setFastestInterval以确保在收到位置更新后迅速将其发送给您。由于实际轮询频率与setInterval(而不是最快间隔)相关,因此您setFastestInterval不应增加电池使用量。

于 2014-01-23T19:20:38.203 回答