Geolocation - Use GPS and Network Provider at the same time in Android

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I have implemented a locationlistener in my app which uses the Network Provider.

This all works fine because i want a location quickly and with GPS Provider it takes ages.

But I ve come to a point in my app where location has to be accurate (max 5-10meters).

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?

So basically:

LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);

Will this work with the same overridden onLocationChanged() ?

And how can I see if the GPS has gotten a Location?

Thanks,

Answers

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.

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.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/4595522/use-gps-and-network-provider-at-the-same-time-in-android

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils