在网络和 GPS 提供商之间切换
我想实现一个 locationListener,它将根据可用性在网络和 GPS 提供商之间切换。
例如,如果未启用 GPS,我希望它使用网络,但一旦 GPS 打开,我希望它停止侦听来自网络的位置更新并开始侦听 GPS。
同样,我希望它在 GPS 关闭后立即开始侦听来自网络的更新。
这可能吗?
子问题
GPS 提供位置修复的速度与网络一样快吗?
I want to implement a locationListener which will switch between network and GPS providers based on availability.
For example if GPS is not enabled I want it to use network but as soon as GPS is on then I want it to stop listening for location updates from network and start listening from GPS.
Similarly I want it to start listening for updates from network as soon as GPS is switched off.
Is that possible?
Subquestion
Is GPS as fast as network in providing a location fix?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当然,您只需获取网络和 GPS 的提供商并将您想要的任何内容传递给
locationManager.requestLocationUpdates()
。当您想要停止侦听某个提供程序时,请使用您在
locationManager.requestLocationUpdates()
中指定的侦听器对象调用locationManager.removeUpdates()
。网络:
GPS:
您可以使用 LocationManager.isProviderEnabled() doc< /a> 查看是否启用/禁用了相应的提供程序。 LocationManager 文档中提供了更多信息。
GPS 通常比网络慢得多,因为您必须找到 3 个以上的遥远卫星等。
Sure, you just get the providers for the network and GPS and pass whichever you want to
locationManager.requestLocationUpdates()
.When you want to stop listening to a certain provider, call
locationManager.removeUpdates()
with the listener object you specified inlocationManager.requestLocationUpdates()
.Network:
GPS:
You can use LocationManager.isProviderEnabled() doc to see if the appropriate provider is enabled/disabled. There's more info available in the LocationManager docs.
GPS is usually much slower than network since you have to find 3+ far-away satellites, etc.
我正在用这个
I am using this