android - requestLocationUpdates minTime 参数用途

标签 android gps locationmanager

我正在创建一个应用程序(用于教育目的),它每 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 个问题:

  1. minTime 参数没有实现其目的,甚至作为提示也没有实现(是的,30 分钟更新率的提示导致超过一秒的更新...)。那它有什么作用呢?
  2. 还有其他方法吗?我不希望 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/

相关文章:

android - Android GPS 定位的 getAltitude() 是如何工作的

iphone - 为什么即使我在后台请求位置更新,我的 iOS 应用程序也会被杀死?

java - 使用 LTE 而不是 WiFi 获取位置数据时遇到问题

android - 为什么我需要 android.permission.ACCESS_CHECKIN_PROPERTIES

大约 2012 年的 Android 支付平台选项

java - 无法将 GPS 坐标发送到服务器

android - 无法解析符号 ReceiveUpdatesIntentService

ios - addressDictionary 随机返回 nil

android - FrameLayout 中的 ScrollView 的问题

android - 共享元素 Activity 转换。当 Activity 被销毁时, View 停留在屏幕上