我在我的应用中实现了一个位置监听器,它使用了网络提供者.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!