Not Gettting Accurate Location In Some Android Phones
Solution 1:
You can not expect the phone neither to always have a valid "last known location" nor to define its location in microseconds.
You first call requestLocationUpdates()
and instantly after that getLastKnownLocation()
. There's no time for the phone to determine/update the "last known location". Besides now you always call requestLocationUpdates()
again and again when you call getLocation()
. Just call it once when you want to start receiving location updates.
Just subscribe to receive location updates once and always get the latest location in the callback that happens with a small delay. You already have the empty onLocationChanged()
method. That is the callback method. Just make that to handle the location updates.
You can of course call removeUpdates()
or removeLocationUpdates()
once you have received the fresh and up-to-date location in the onLocationChanged()
callback if you don't want to receive any further updates.
Some useful Stackoverflow discussions:
How to get location that isn't out of date?
Android: getLastKnownLocation out-of-date - how to force location refresh?
Post a Comment for "Not Gettting Accurate Location In Some Android Phones"