問題描述
我在我的應(yīng)用中實現(xiàn)了一個位置監(jiān)聽器,它使用了網(wǎng)絡(luò)提供者.
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.
但我的應(yīng)用程序中的位置必須準確(最大 5-10 米).
But I've come to a point in my app where location has to be accurate (max 5-10meters).
我想知道是否可以同時使用 GPS 提供商和網(wǎng)絡(luò)提供商,然后獲得兩者的最佳結(jié)果?是否也可以讓我知道 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?
謝謝,
推薦答案
你當然可以為多個提供者使用同一個監(jiān)聽器.最好將 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
回調(diào)為您提供一個 Location 對象,該對象有一個 getProvider()
方法,您可以使用它來確定它來自哪里.它還有一個 getAccuracy()
方法,因此您還可以按準確性對最近的修復(fù)進行排序.
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.
這篇關(guān)于在 Android 中同時使用 GPS 和 Network Provider的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!