Location Data Access
Get the Last Known Location
getLastKnownLocation() delivers the most recent location currently available through its callback. It does not calculate a new location, and the LocationData? value may be null when location data is unavailable.
Receive Location Updates
Pass a FusedLocationListener to registerFusedLocationCallback() to receive onChanged(LocationData?) when location data changes. The SDK calls onError(Exception) when an error occurs.
val listener = object : FusedLocationListener {
override fun onChanged(location: LocationData?) {
location ?: return
// Use the location data.
}
override fun onError(exception: Exception) {
// Handle the error.
}
}
fusedLocation.registerFusedLocationCallback(listener)
Stop Location Updates
When updates are no longer needed, pass the same listener used for registration to unregisterFusedLocationCallback().
fusedLocation.unregisterFusedLocationCallback(listener)
See Declaring Permission for the permissions required by these APIs.