GetLastKnownLocation () Android, when is the last known location updated?

getBestKnownLocation Returns a location indicating data from the last known location fix received from this provider. This can be done without starting the provider. Please note that this location may be outdated, for example, if the device was turned off and moved to another location.

When is the last known location updated in Android? Is this updated when the application that listens to the location provider, if so, what if there is no application that it requests, and then you requested LastKnownLocation ()?

+8
android location
source share
2 answers

I think LastKnownLocation () is updated when some programs on your phone use this requestLocationUpdates function.

+5
source share

See Start a Location Strategy

I did some research: I turned on the GPS and waited for a fix. Then I turned off the GPS and drove 50 km (31 miles). Then I used the code from A Deep Dive Into Location to get all getLastKnownLocation. I tried this twice, first with GPS turned off and second with GPS turned on, but without a fix:

1) when GPS is disabled, I got - Provider: network, correct location with an accuracy of 680 m - Provider: passive (mProvider = network), same place as above, at the same time as above - Provider: gps location null

So, I found out that when gps is disabled, you are not getting getLastKnownLocation from the GPS location provider.

2) with GPS on - Provider: network, correct location with an accuracy of 652 m - Provider: passive (mProvider = network), the same place as above, at the same time as above - Provider: gps, location, as was 2 hours earlier with an accuracy of 12 m, time was 2 hours earlier

Here I learned that old messages are not invalid, it’s even obvious that they are wrong.

So, to summarize: when the provider is active, it stores the last received location returned via getLastKnownLocation. If the provider is disabled, you do not even get getLastKnownLocation. Please note that I tested this with a GPS provider, other providers may react differently.

+5
source share

All Articles