Use GPS and Network Provider at the same time in Android(在 Android 中同时使用 GPS 和 Network Provider)
问题描述
我在我的应用中实现了一个位置监听器,它使用了网络提供者.
I have implemented a locationlistener in my app which uses the Network Provider.
这一切都很好,因为我想要一个快速的位置,并且使用 GPS 提供程序需要很长时间.
This all works fine because i want a location quickly and with GPS Provider it takes ages.
但我的应用程序中的位置必须准确(最大 5-10 米).
But I've come to a point in my app where location has to be accurate (max 5-10meters).
我想知道是否可以同时使用 GPS 提供商和网络提供商,然后获得两者的最佳结果?是否也可以让我知道 GPS 提供商何时向我提供了 GPS 位置?
I was wondering if it's possible to use the GPS provider with the Network Provider at the same time and then get the best result of both? And is it also possible to let me know when the GPS provider provided me with an GPS Location?
所以基本上:
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
这是否适用于相同的覆盖 onLocationChanged() ?
Will this work with the same overridden onLocationChanged() ?
我如何查看 GPS 是否获得了位置信息?
And how can I see if the GPS has gotten a Location?
谢谢,
推荐答案
你当然可以为多个提供者使用同一个监听器.最好将 locationmanager.getProviders
与 Criteria
对象一起使用,然后按准确性排序或只听所有这些对象.不过实际差别不大.
You can certainly use the same listener for multiple providers. It may be better to use locationmanager.getProviders
with a Criteria
object then sort by accuracy or just listen to all of them. Not much practical difference though.
onLocationChanged
回调为您提供一个 Location 对象,该对象有一个 getProvider()
方法,您可以使用它来确定它来自哪里.它还有一个 getAccuracy()
方法,因此您还可以按准确性对最近的修复进行排序.
The onLocationChanged
callback gives you a Location object, which has a getProvider()
method you can use to determine where it came from. It also has a getAccuracy()
method, so you could also sort your recent fixes by accuracy.
这篇关于在 Android 中同时使用 GPS 和 Network Provider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Android 中同时使用 GPS 和 Network Provider


- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01