Skip to content Skip to sidebar Skip to footer

Android: Getlastknownlocation Out-of-date - How To Force Location Refresh?

I'm using myLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); to retrieve the current location at the start-up of my application. As the Android docu

Solution 1:

Your initial intuition is correct - you need to use a LocationListener to request updates. Given that you require only a single position, you can unregister the LocationListener after the first value returns.

In practice though, it's probably wise to listen for a little bit longer. Location Based Services (particularly GPS) have a tendency to 'jump around' a bit when they first get their fix. Your best bet is to listen for a set amount of time, or a set number of updates, or until a certain level of accuracy has been achieved (the Location Listener will return the accuracy of the position returned).

Post a Comment for "Android: Getlastknownlocation Out-of-date - How To Force Location Refresh?"