Skip to content Skip to sidebar Skip to footer

Not Gettting Accurate Location In Some Android Phones

I have used below code. It work fine but in some devices like Redme,Asus not getting accurate location.It shown me too far from my current location aprox 20 km away.Not getting whe

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?

Android - Reliably getting the current location

Post a Comment for "Not Gettting Accurate Location In Some Android Phones"