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


基础教程推荐
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01