How To Get Location That Isn't Out Of Date?
After GPS is enabled, it will take some time before the GPS is ready. So use this code may get a location that is out of date: location = locationManager.getLastKnownLocation(Locat
Solution 1:
How to get location that isn't out of date?
You call requestLocationUpdates()
with the minTime of 1000 ms, for every Location
in onLocationChanged()
, you call getAccuracy()
. If the accuracy is acceptable for you, call removeUpdates()
.
So I can't use this method to judge whether the return value of getLastKnownLocation() is not out-of-date
I think the Location object that it returns will contain a time stamp. You can set a tolerance for the time difference between now and the Location's getTime()
Solution 2:
Each Location
object has a getTime()
method, which returns the time of the fix. You could use that to determine how old the fix is.
Post a Comment for "How To Get Location That Isn't Out Of Date?"