使用带有 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 this
和 System.out.println()
有什么区别:)
关于android - requestLocationUpdates 与位置监听器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16444256/