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.
LocationManager#requestLocationUpdates允许您传入minTime和minDistance参数。我很难决定这些数字应该是什么,并且可以欣赏一些指导。
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.
我们的应用程序不是一个转弯导航应用程序;我只是想展示10个最近的景点。由于我显示最近的10,它们可能会变得有点陈旧,但如果用户在移动的车辆中,我想/需要经常更新它们以避免陈旧。
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?
我想很多人都处于模糊要求的同一位置:“我不希望数据过于陈旧,但我不想浪费电池。”如何将这些模糊的要求转化为具体数字?
4 个解决方案
#1
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.
基于你的问题,听起来像minTime参数是无关紧要的。
What you really need to worry about is minDistance, so that if a user is in a fast moving vehicle, it will keep up.
您真正需要担心的是minDistance,因此如果用户处于快速移动的车辆中,它将会跟上。
If a person is driving 60 MPH, they move about 27 meters per second.
如果一个人驾驶60英里/小时,他们每秒移动约27米。
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
minTime = 60000 //每隔60秒更新minDistance = 90 //在快速移动的车辆中,它将每3秒大致更新一次
#2
3
It has been described nicely in requestLocationUpdates docs
在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.
可以使用minTime和minDistance参数来控制通知的频率或新位置。如果minTime大于0,则LocationManager可能会在位置更新之间休息几分钟,以节省电量。如果minDistance大于0,则仅当设备移动minDistance米时才会广播位置。要尽可能频繁地获取通知,请将两个参数都设置为0.后台服务应该注意设置足够高的minTime,以便设备不会通过始终保持GPS或无线无线电而消耗太多电量。特别是,不推荐低于60000ms的值。
#3
1
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.
我可以建议一个更好的想法,最初请求更大的间隔更新并获取位置。现在检查连续位置之间的距离是否大于区分较近位置的最小距离,将请求更新间隔更改为较低值。类似地,如果在该较低的间隔中,您计算的距离远低于指示用户未通过车辆行驶的距离,则将间隔更新为更大的值。要更新间隔,您必须取消注册上一个侦听器,然后使用新值重新注册。
#4
0
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.
对于您手头的问题,请查看PASSIVE_PROVIDER。基本上,当任何其他应用程序可能要求更新时,它将帮助您获得更新。因此,您可以将其与其他提供商结合使用。
#1
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.
基于你的问题,听起来像minTime参数是无关紧要的。
What you really need to worry about is minDistance, so that if a user is in a fast moving vehicle, it will keep up.
您真正需要担心的是minDistance,因此如果用户处于快速移动的车辆中,它将会跟上。
If a person is driving 60 MPH, they move about 27 meters per second.
如果一个人驾驶60英里/小时,他们每秒移动约27米。
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
minTime = 60000 //每隔60秒更新minDistance = 90 //在快速移动的车辆中,它将每3秒大致更新一次
#2
3
It has been described nicely in requestLocationUpdates docs
在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.
可以使用minTime和minDistance参数来控制通知的频率或新位置。如果minTime大于0,则LocationManager可能会在位置更新之间休息几分钟,以节省电量。如果minDistance大于0,则仅当设备移动minDistance米时才会广播位置。要尽可能频繁地获取通知,请将两个参数都设置为0.后台服务应该注意设置足够高的minTime,以便设备不会通过始终保持GPS或无线无线电而消耗太多电量。特别是,不推荐低于60000ms的值。
#3
1
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.
我可以建议一个更好的想法,最初请求更大的间隔更新并获取位置。现在检查连续位置之间的距离是否大于区分较近位置的最小距离,将请求更新间隔更改为较低值。类似地,如果在该较低的间隔中,您计算的距离远低于指示用户未通过车辆行驶的距离,则将间隔更新为更大的值。要更新间隔,您必须取消注册上一个侦听器,然后使用新值重新注册。
#4
0
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.
对于您手头的问题,请查看PASSIVE_PROVIDER。基本上,当任何其他应用程序可能要求更新时,它将帮助您获得更新。因此,您可以将其与其他提供商结合使用。