我可以使用 LocationManager 获取 minDistance 和 minTime 的位置。
但是,例如,我如何才能每 15 秒获取一次位置? (即使用户没有移动)
if (Utils.hasProvider(LocationManager.GPS_PROVIDER)) {
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 15000, 100f, this);
}
if (Utils.hasProvider(LocationManager.NETWORK_PROVIDER)) {
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 15000, 100f, this);
}
最佳答案
谷歌文档说
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.
因此涉及到一个 AND 条件。因此,您应该将距离参数设置为 0。在这种情况下,您将每 15 秒更新一次位置。
关于java - Android - 一段时间后获取位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33014829/