gpt4 book ai didi

android - requestLocationUpdates 与位置监听器

转载 作者:行者123 更新时间:2023-11-29 18:00:30 30 4
gpt4 key购买 nike

使用带有 requestLocationUpdates() 的位置管理器对象与仅使用 LocationListener 有什么区别?他们都做同样的事情并且以同样的方式工作吗?一个比另一个有什么优势?

LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

lm.requestLocationUpdates(LocationManager.GPS_provicer, 0, 0, new LocationListener()){
//all appropriate methods here
}

对比

LocationListener myLocationListener = New LocationListener(){
// all appropriate methods here
}

最佳答案

您的问题在技术上是不正确的。 LocationManager 通过 requestLocationUpdates 注册一个监听器。当您的位置管理器意识到超时或距离旅行已经发生时,监听器是回调。在您的情况下,将立即调用位置监听器。

但请注意,带有0,0 参数的位置管理器请求更新是即时的。有时可能会有延迟。

所以您关于有什么区别的问题是不正确的。这就像问 Print thisSystem.out.println() 有什么区别:)

关于android - requestLocationUpdates 与位置监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16444256/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com