I'm using google api fused location. I would like to get the current location with high accuracy without continuously track location with LocationListener interface.
I have a simple use case : A user tap on the button, the application would display the current latitude and longitude (fresh location).
Then, is getLastLocation() retrieve the location from a cache (which mean it can't be accurate in some case) or make a location request to get a fresh data ?
If no, is it possible to achieve my use case without to implement LocationListener interface ?
As per the documentation on the andoid website.
To request the last known location, call the getLastLocation() method, passing it your instance of the GoogleApiClient object. Do this in the onConnected() callback provided by Google API Client, which is called when the client is ready. The following code snippet illustrates the request and a simple handling of the response:
This means it will not update the location when you call getLastLocation()
. This will be done on an update based service.
You can request location updates with this function
protected void startLocationUpdates() {
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
}