Reputation: 79
I've an app which allows usage if user is in certain area, meaning I don't need to track the user, but I need to make sure location that's received is fresh (even if it requires waiting).
What's the best way to do this? Currently using:
getLastLocation()
but it can sometimes get previous location, understandably.
Upvotes: 1
Views: 133
Reputation: 790
You can register a location listener and proceed to the code if the location condition is met:
locationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
if (locationResult == null) {
return;
}
for (Location location : locationResult.getLocations()) {
//if(this is the location) jump to the code which makes the app usable
}
//stay unusable
};
};
getting the location might take some time. If by force you mean holding the ui thread until the precise-enough location is available then force getting the location is a bad but feasible idea.
Upvotes: 1