【发布时间】:2014-01-23 19:11:45
【问题描述】:
我正在使用 LocationClient 每分钟获取当前位置:
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);
但是我注意到我的 LocationListener 的 onLocationChanged 方法每 60 或 120(或 60 的任何其他倍数)秒(+/- 3 秒)调用一次。文档说:
这个间隔是不准确的。您可能根本不会收到更新(如果没有可用的位置资源),或者您收到更新的速度可能比请求的慢。 [...]
所以我知道,间隔不是精确的一分钟。但我认为我会在 60 秒结束后尽快获得当前位置,例如 75 秒后。但是,如果 LocationClient 无法确定位置,它似乎会在接下来的 60 秒后重试。
这个假设正确吗?
如果是,解决方法是将间隔设置为较低的值,例如 30 秒左右,并在 onLocationChanged 方法中过滤掉所需的位置。但这可能会消耗更多的电池电量。
【问题讨论】:
标签: android google-play-services location-client