I've been using locationAvailability.isLocationAvailable()
from FusedLocationProviderClient, and it has been working fine. However, today we noticed that it always returns false initially, even though the location is still retrieved after about 3 seconds.
This happens across all Android devices(tested on Samsung and Oppo) and OS versions (Android 11-15), and location services are confirmed to be enabled.
There have been no recent changes in our location-related logic or library updates.
Is this expected behavior, or has something changed recently?
My gms:play-services-location version:
com.google.android.gms:play-services-location:21.3.0
My code:
private val locationCallback: LocationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult) {
super.onLocationResult(locationResult)
val location = locationResult.lastLocation
if (location != null) {
//some logic. This will be triggered after a few seconds
} else {
//some logic
}
}
override fun onLocationAvailability(locationAvailability: LocationAvailability) {
super.onLocationAvailability(locationAvailability)
if (!locationAvailability.isLocationAvailable) {
noLocationAcquired() //This will be triggered instantly
}
}
}
From the the official documentation:
When LocationAvailability.isLocationAvailable() returns false it generally indicates that further invocations of onLocationResult(LocationResult) are unlikely until something changes with the device's settings or environment.
In my case, onLocationResult(LocationResult
) is still triggered after a few seconds, even though LocationAvailability.isLocationAvailable()
returns false
initially.
This issue started happening only recently, and our production users are affected on both old and new versions of the app.
I’d appreciate any feedback. Thanks!