Android LocationListener LocationCallback的区别是什么?
我一直在看和玩。该类包含以下两种方法:Android LocationListener LocationCallback的区别是什么?,android,google-play-services,google-location-services,Android,Google Play Services,Google Location Services,我一直在看和玩。该类包含以下两种方法: PendingResult<Status> requestLocationUpdates(GoogleApiClient client, LocationRequest request, LocationCallback callback, Looper looper) PendingResult<Status> requestLocationUpdates(GoogleApiClient client, LocationRequ
PendingResult<Status> requestLocationUpdates(GoogleApiClient client, LocationRequest request, LocationCallback callback, Looper looper)
PendingResult<Status> requestLocationUpdates(GoogleApiClient client, LocationRequest request, LocationListener listener, Looper looper)
void onLocationAvailability(LocationAvailability locationAvailability)
void onLocationResult(LocationResult result)
接口LocationListener
只定义了一种方法
abstract void onLocationChanged(Location location)
忽略
LocationCallback
中的附加方法,这两者之间有什么区别?是否存在一些概念上的差异或特殊用例,使一个优于另一个?复制功能的基本原理是什么?您会注意到,onLocationResult()
返回一个-这使得同时接收多个位置变得更容易-如果您通过设置正确批处理位置请求,您将经常遇到这种情况
如果您选择使用较旧的
LocationListener
,在批处理时,您将收到多个对onLocationChanged()
的回调。Hmm。此批处理看起来很有趣。如果我做对了,我可以发出间隔为10秒的LocationRequest,并将MaxWaitTime设置为100秒,然后在一个LocationResult中获取所有10个(或更多或更少)位置。可能有用。向上投票,对!在许多现代手机上,分批处理是直接在GPS芯片上完成的,这意味着主CPU在分批之间根本不需要唤醒,从而带来了一些令人印象深刻的电池改进。我非常喜欢简短的答案,这些答案能准确地告诉我需要知道什么!我正在使用locationcallback,我希望每秒钟都能得到位置更新,为此,我在locationrequest对象中添加了1秒的间隔作为locationrequest=new locationrequest().setInterval(1000).setPriority(locationrequest.PRIORITY\u HIGH\u精度).SetFastTestInterval(1000)代码>但我仍然每10秒更新一次位置。你能解释一下为什么会这样吗@ianhanniballake@JaydipKalkani-setInterval
文档特别指出“此时间间隔不准确。您可能根本无法接收更新(如果没有可用的位置源),或者您接收更新的速度可能比请求的慢”