I have a Service implementing LocationListener listening for both GPS and Network.
The application is dependant on a constant location-feed, but it seems when GPS has a hard time getting a locationfix network location doesnt step in.
manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000 * 30,0, LocationReporterService.this);
manager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000 * 60 * 2,0, LocationReporterService.this);
Questions
How do I make sure that I always get a location?
How can I make sure that if I dont get a GPS-location, I get a Network-location?
Is it a known bug?
Should I have 2 services, GPSLocationService and NetworkLocationsService?
Is there a solution to this? 🙂
I agree with most of comments from AlexBottoni good answer, although in some points I can’t suppot him.
Overview
First, just to check that you are doing it right…
You setup the same
LocationListenerfor both providers. To indentify from where you are reciving the location you need to test it like this:Also, you setup a different acquisition frequency.
Gpsis providing a new location every 30 seconds andNetworkevery 2 minutes.As you didn’t impose a minimum distance, you should receive a new
Locationfrom each one of the providers (as long as they can get a fix) with the frequency requested. If you don’t receive a fix, is because they weren’t able to acquire one.Also, it may takes a little longer then requested to get the fix (mainly with Gps), because it may take some time to shyncronize with satellites and fix a location.
Fallback
There is no builted-in fallback from one provider to the other. They are independet, as said by Alex. I’m using the following approach to implement fallback:
Preferable Provider
Although
Gpsmay not be available everyhere, is far most precise thenNetwork. In my town, I get 6 meters accuracy with GPS and 1 Km with Network 🙁Two services
Doesn’t matter where you register the listener, activity or service, separate ot together, as long as you request them and the provider can get a fix, you will get the location (assuming no bugs in application :-))
Final Notes
Ensure you have the permissions need (ACCESS_FINE_LOCATION, INTERNET, etc).
Ensure that phone setup have Network Location enabled (usually default is disable)
Most Gps receivers support updating information about satellite location, which improves fix time. You can use
GPS Satusfrom the market, to do it.Regards.