指定位置管理器在 Android 中广播当前位置的时间间隔
有没有办法指定位置管理器广播当前位置的时间间隔?
我正在使用一种名为 startListening 的方法:
public void startListening() {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
this
);
}
谢谢
Is there any way to specify the time intervals that the Location Manager broadcasts the current location?
I am using a method called startListening:
public void startListening() {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
this
);
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
public void requestLocationUpdates (Stringprovider, long minTime, float minDistance, LocationListenerlistener, Looperlooper)
注册当前活动,由指定的提供程序定期通知。将定期使用当前位置或状态更新来调用所提供的 LocationListener。
可能需要一段时间才能收到最新位置。如果需要立即位置,应用程序可以使用 getLastKnownLocation(String) 方法。
如果用户禁用提供程序,更新将停止,并且将调用
onProviderDisabled(String)
方法。一旦再次启用提供程序,就会调用 onProviderEnabled(String) 方法,并且位置更新将再次开始。可以使用
minTime
和minDistance
参数控制通知的频率。如果minTime
大于 0,LocationManager 可能会在位置更新之间休息minTime
毫秒以节省电量。如果minDistance
大于 0,则仅当设备移动minDistance
米时才会广播位置。要尽可能频繁地获取通知,请将这两个参数都设置为 0。后台服务应谨慎设置足够高的
minTime
,以便设备不会因保持 GPS 或无线电而消耗太多电量一直开着。特别是,不建议使用低于 60000ms 的值。提供的Looper用于实现回调机制。
参数
用来注册
最小时间间隔
通知,以毫秒为单位。这
字段仅用作提示
节省电量和实际时间
位置更新之间可能是
大于或小于该值。
通知间隔,以米为
每个方法都会被调用
位置更新
其消息队列将是的对象
用于实现回调
机制。
抛出
如果提供程序为 null 或不存在,则
IllegalArgumentException
IllegalArgumentException
如果侦听器为 nullIllegalArgumentException
如果循环器为空SecurityException
如果提供者没有合适的权限。public void requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener, Looper looper)
Registers the current activity to be notified periodically by the named provider. Periodically, the supplied LocationListener will be called with the current Location or with status updates.
It may take a while to receive the most recent location. If an immediate location is required, applications may use the getLastKnownLocation(String) method.
In case the provider is disabled by the user, updates will stop, and the
onProviderDisabled(String)
method will be called. As soon as the provider is enabled again, the onProviderEnabled(String) method will be called and location updates will start again.The frequency of notification may be controlled using the
minTime
andminDistance
parameters. IfminTime
is greater than 0, the LocationManager could potentially rest forminTime
milliseconds between location updates to conserve power. IfminDistance
is greater than 0, a location will only be broadcasted if the device moves byminDistance
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.The supplied Looper is used to implement the callback mechanism.
Parameters
with which to register
minimum time interval for
notifications, in milliseconds. This
field is only used as a hint to
conserve power, and actual time
between location updates may be
greater or lesser than this value.
interval for notifications, in meters
method will be called for each
location update
object whose message queue will be
used to implement the callback
mechanism.
Throws
IllegalArgumentException
if provider is null or doesn't existIllegalArgumentException
if listener is nullIllegalArgumentException
if looper is nullSecurityException
if no suitable permission is present for the provider.minTime :通知的最小时间间隔,以毫秒为单位。该字段仅用作节省电量的提示,位置更新之间的实际时间可能大于或小于该值。
minDistance:通知的最小距离间隔,以米为单位
minTime : the minimum time interval for notifications, in milliseconds. This field is only used as a hint to conserve power, and actual time between location updates may be greater or lesser than this value.
minDistance: the minimum distance interval for notifications, in meters
// 60000 是 1 分钟,100 是公里
上面有 9000(九秒)和 500(如果位置移动超过 500 公里)
// 60000 Is 1 Minute and 100 is KM
Above you have 9000 (Nine Seconds) and 500 which is if the location has moved more than 500KM