Question

[Solved] getLastKnownLocation() Android, when the Last Known Location is updated?

getBestKnownLocation Returns a Location indicating the data from the last known location fix obtained from the given provider. This can be done without starting the provider. Note that this location could be out-of-date, for example if the device was turned off and moved to another location.

when the Last Known Location updated in Android? is it updated if when there’s an application listening for the location provider, if so what if there’s no application that it ask for the location and then you asked for LastKnownLocation() ?

Enquirer: Jimmy

||
Solution #1:

I thinki LastKnownLocation() is updating when some programs in your phone use this function requestLocationUpdates.

Respondent: George
Solution #2:

Please see Start location strategy

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

1) with GPS turned off I got
– Provider: network, correct location with accuracy 680m
– Provider: passive (mProvider=network), same location as above, same time as above
– Provider: gps, location null

So I learned that when gps is turned off you get no getLastKnownLocation from the GPS location provider.

2) with GPS turned on I got
– Provider: network, correct location with accuracy 652m
– Provider: passive (mProvider=network), same location as above, same time as above
– Provider: gps, location as it was 2h earlier with accuracy 12m, time was also 2h earlier

Here I learned that old messages are not invalidated, even it is obvious that they are wrong.

So to sum it up: when a provider is active, it stores the last received location retreivable via getLastKnownLocation. If the provider is deactivated, you don’t even get getLastKnownLocation.

Please note that I tested this with the GPS-Provider, other providers may react in a different way.

Respondent: ChrLipp
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy