我正在创建一个应用程序(用于教育目的),它每 30 分钟记录一次用户的位置,并使用户能够查看 map 上的所有位置。我不希望更新频率超过 30 分钟,但确实如此。
这就是我调用 requestLocationUpdates
的方式:
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30 * 60 * 1000, 0, pe);
现在,文档清楚地说:
The elapsed time between location updates will never be less than minTime
但我确实在这里看到了一些关于 SO 的不同说明的答案(例如 This answer)。
似乎只要 GPS 可用,我就会收到更新。 GPS 图标永远不会关闭,更新率变得大于 1 次更新/秒。所以我在这里有 2 个问题:
minTime
参数没有实现其目的,甚至作为提示也没有实现(是的,30 分钟更新率的提示导致超过一秒的更新...)。那它有什么作用呢?- 还有其他方法吗?我不希望 GPS 一直处于启用状态,因为它会消耗我的电池太快。也许我可以安排闹钟每 30 分钟重复一次,然后调用
requestSingleUpdate
?
最佳答案
The minTime parameter doesn't fulfill its purpose, not even as a hint (Yea, a hint to 30 minutes update rate leads to more than update a second...). What does it do, then?
从 Jellybean 开始,设备必须遵守 minTime
参数,因此它确实有目的(现在)。
Is there any other way to do it? I don't want the GPS to be enabled all the time because it will consume my battery too fast. Maybe I could schedule alarms repeating each 30 minutes, and call requestSingleUpdate?
是的,使用处理程序每 30 分钟通过 requestSingleUpdate()
请求一次更新。
我之前在 previous question 中解决过这个问题,让我知道该答案中的代码是否有帮助,如果您有任何 Unresolved 问题。
关于android - requestLocationUpdates minTime 参数用途,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13555153/