Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Android LocationManager has long delay before location updates start if setting accuracy

If I set any ACCURACY to criteria, it takes long time to LocationManager to start updating location:

Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
provider = locationManager.getBestProvider(criteria, true);
locationManager.requestLocationUpdates(provider, 0, 0, this);

If I remove ACCURACY flag, it starts immediately but sometimes not accurate.

How can I make it start updating immediately and with good accuracy?

like image 488
Misha Avatar asked Jun 22 '13 09:06

Misha


People also ask

How will you instantly at location manager object?

First, create a Location Manager object by calling the getSystemService() method and LOCATION_SERVICE as an argument. Call getBestProvider() to get the location in the form of a string. Now the provider to getLastKnownLocation() as an argument to get the location.

Which interface do we use to get the location updates?

This class provides access to the system location services. These services allow applications to obtain periodic updates of the device's geographical location, or to be notified when the device enters the proximity of a given geographical location.

How do I get accuracy on my Android?

You can get your accuracy info from Location. getAccuracy() or from NMEA data. Once you've started getting fixes it won't take much time. Time to first fix can be 30 seconds to 15 minutes.


3 Answers

Unfortunately, no way.

If you use ACCURACY_FINE, you will use GPS only, but GPS have "cold start" effect. It means that if you device not used GPS long time, it needs a lot of time for connecting with satellites and download almanac and ephemeris. You can't change this behavior.

If you don't use ACCURACY_FINE, you will use both GPS and network (mobile, wi-fi) signals. So you will receive quick first position from network, because they don't have "cold start" effect, but accuracy of this method is low. When your GPS module will ready, you will start receive updates from it too.

like image 56
Dimmerg Avatar answered Nov 14 '22 21:11

Dimmerg


If you care only about accuracy and not things like bearing or altitude I suggest switching to the new fused provider in the LocationClient API from Google.

It is very quick to get the first fix, more accurate than network based and doesn't depend on GPS.

It requires a bit more setup then the built-in LocationManager, so you may read this training article: http://developer.android.com/training/location/receive-location-updates.html

like image 33
MaciejGórski Avatar answered Nov 14 '22 23:11

MaciejGórski


I suspect that at least with ACCURACY_FINE, it's waiting to get an initial GPS fix. You may find that if you've already got GPS turned on for another reason (e.g. if you're in the middle of navigation) that it starts reporting immediately.

It can take a while to get a GPS fix - I think it's just a natural part of how GPS works.

like image 28
Jon Skeet Avatar answered Nov 14 '22 23:11

Jon Skeet