Why does the Android LocationManager have a long delay before the location update starts, if you set the accuracy

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

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

If I remove the ACCURACY flag, it will start immediately, but sometimes not exactly.

How can I get him to start the update immediately and with good accuracy?

+4
source share
4 answers

Unfortunately, in no way.

If you use ACCURACY_FINE , you will only use GPS, but GPS has a cold start effect. This means that if the device does not use GPS for a long time, it needs a lot of time to connect with satellites and download the almanac and ephemeris. You cannot change this behavior.

If you do not use ACCURACY_FINE , you will use both GPS and network (mobile, Wi-Fi) signals. Thus, you will get a fast first position from the network because they do not have a cold start effect, but the accuracy of this method is low. When your GPS module is ready, you will also begin to receive updates from it.

+6
source

If you care only about accuracy, and not about things, for example, bearings or height, I suggest switching to a new smooth provider in Google's LocationClient API .

It’s very fast to get the first patch, more accurate than the network one, and not dependent on GPS.

This requires a bit more customization than the built-in LocationManager , so you can read this tutorial article: http://developer.android.com/training/location/receive-location-updates.html p>

+3
source

I suspect that at least with ACCURACY_FINE , he is waiting to get the initial GPS fix. You may find that if you already turned on GPS for another reason (for example, if you are in the middle of navigation), it immediately starts reporting.

It may take some time to get the GPS fix. I think this is just a natural part of GPS work.

+2
source

LocationManager does not work on many phones, as it is highly dependent on custom open source Android code for specific equipment. Samsung phones are very distorted when it comes to LocationManager .

You should not use requestLocationUpdates , use getLastKnownLocation with a little hack instead. Before calling getLastKnownLocation enter the following hack and you can use AlarmManager to receive regular updates.

 HomeScreen.getLocationManager().requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(final Location location) { } }); 

LocationClient is another alternative to LocationManager . More precisely, it uses hi a lot less battery.

+1
source

Source: https://habr.com/ru/post/1487602/


All Articles