如何确定 requestLocationUpdates 使用的时间间隔?
< code>LocationManager#requestLocationUpdates 允许您传入 minTime 和 minDistance 参数。我很难决定这些数字应该是什么,并且希望得到一些指导。
我们的应用程序不是路线导航应用程序;我只想显示最近的 10 个兴趣点。由于我显示的是最近的 10 个,它们可能会有点陈旧,但如果用户在移动的车辆中,我希望/需要经常更新它们以避免陈旧。
我想很多人都处于同样的模糊需求位置:“我不想数据太陈旧,但我不想浪费电池。”如何将这些模糊的要求转化为具体的数字?
LocationManager#requestLocationUpdates
allows you to pass in a minTime and minDistance parameter. I'm having a hard time deciding what these numbers should be, and could appreciate some guidance.
Our app is not a turn-by-turn navigation app; I just want to show the 10 nearest points of interest. Since I'm showing the 10 nearest, they can get a little stale, but if the user is in a moving vehicle, I'd want/need to update them pretty frequently to avoid staleness.
I imagine a lot of people are in the same position of vague requirements: "I don't want the data to be too stale, but I don't want to waste battery." How can I turn these vague requirements into concrete numbers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据您的问题,在我看来, minTime 参数是无关紧要的。
您真正需要担心的是 minDistance,这样如果用户处于快速移动的车辆中,它就会跟上。
如果一个人以 60 英里每小时的速度行驶,他们每秒移动约 27 米。
考虑到这个标准...我会说使用:
minTime = 60000 // 每 60 秒更新一次
minDistance = 90 // 在快速移动的车辆中,大约每 3 秒更新一次
Based on your problem, it sounds to me like the minTime parameter is irrelevant.
What you really need to worry about is minDistance, so that if a user is in a fast moving vehicle, it will keep up.
If a person is driving 60 MPH, they move about 27 meters per second.
Considering this critera... I would say to use:
minTime = 60000 // update every 60 seconds
minDistance = 90 // in a fast moving vehicle, it will update roughly once every 3 seconds
requestLocationUpdates 文档
It has been described nicely in requestLocationUpdates docs
我可以提出一个更好的想法,即最初以更大的间隔请求更新并获取位置。现在检查连续位置之间的距离是否大于区分较近位置的最小距离,将请求更新间隔更改为较低的值。类似地,如果在这个较低的间隔中,您计算的距离要低得多,表明用户没有通过车辆行驶,则将间隔更新为更大的值。
要更新间隔,您必须取消注册以前的侦听器,然后使用新值重新注册。
I can suggest a better idea that, initially request updates with a little larger interval and get the locations. Now check if the distance between the consecutive locations is more than the minimum distance to distinguish the nearer locations, change your request update interval to lower value. Similarly if in this lower interval the distance you computed of much lower that indicates the user in not traveling through vehicle then update interval to larger value.
To update the interval you have to unregister previous listener and then re-regiser with new value.
对于您手头的问题,请查看 PASSIVE_PROVIDER 。基本上,当任何其他应用程序可能请求更新时,它会帮助您获取更新。因此,您可以与其他提供商结合使用。
For your problem at hand, do take a look at the PASSIVE_PROVIDER. Basically it will help you get updates when any other apps might request for them. So, you can use this in conjunction with other provider.