如何确定 requestLocationUpdates 使用的时间间隔?

发布于 2024-11-16 16:19:57 字数 473 浏览 2 评论 0原文

< 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陪你搞怪i 2024-11-23 16:19:57
***<Edit>***
As of JellyBean, the criteria is (minTime & minDistance), so it has 
to satisfy both to return a location.
***</Edit>***

根据您的问题,在我看来, minTime 参数是无关紧要的。

您真正需要担心的是 minDistance,这样如果用户处于快速移动的车辆中,它就会跟上。

如果一个人以 60 英里每小时的速度行驶,他们每秒移动约 27 米。

考虑到这个标准...我会说使用:

minTime = 60000 // 每 60 秒更新一次
minDistance = 90 // 在快速移动的车辆中,大约每 3 秒更新一次

***<Edit>***
As of JellyBean, the criteria is (minTime & minDistance), so it has 
to satisfy both to return a location.
***</Edit>***

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

浅暮の光 2024-11-23 16:19:57

requestLocationUpdates 文档

通知或新通知的频率
位置可以使用控制
minTime 和 minDistance 参数。如果
minTime 大于 0,则
LocationManager 可能会休息
之间的 minTime 毫秒
位置更新以节省电量。如果
minDistance 大于 0,a
仅当以下情况时才会广播位置:
设备移动 minDistance 米。到
获取通知的频率为
如果可能,请将两个参数都设置为 0。
后台服务要小心
关于设置足够高
minTime 以便设备不会
通过保持消耗过多的电力
所有设备均配备 GPS 或无线电
时间。特别是,以下值
不推荐60000ms。

It has been described nicely in requestLocationUpdates docs

The frequency of notification or new
locations may be controlled using the
minTime and minDistance parameters. If
minTime is greater than 0, the
LocationManager could potentially rest
for minTime milliseconds between
location updates to conserve power. If
minDistance is greater than 0, a
location will only be broadcast if the
device moves by minDistance meters. To
obtain notifications as frequently as
possible, set both parameters to 0.
Background services should be careful
about setting a sufficiently high
minTime so that the device doesn't
consume too much power by keeping the
GPS or wireless radios on all the
time. In particular, values under
60000ms are not recommended.

甜宝宝 2024-11-23 16:19:57

我可以提出一个更好的想法,即最初以更大的间隔请求更新并获取位置。现在检查连续位置之间的距离是否大于区分较近位置的最小距离,将请求更新间隔更改为较低的值。类似地,如果在这个较低的间隔中,您计算​​的距离要低得多,表明用户没有通过车辆行驶,则将间隔更新为更大的值。
要更新间隔,您必须取消注册以前的侦听器,然后使用新值重新注册。

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.

櫻之舞 2024-11-23 16:19:57

对于您手头的问题,请查看 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文