androidgoogle-mapskotlinfusedlocationproviderapiandroid-fusedlocation

FusedLocationProviderClient always reports LocationAvailability false


I have an app which has been live for a couple of years now, but lately, I've been getting reports about the location system not functioning properly. I have tracked the issue down to the LocationCallback.onLocationAvailability(availability: LocationAvailability?). it is always called with availability.isLocationAvailable = false

The description indicates that it being false, means that i cannot count on getting any locations from the other function LocationCallback.onLocationResult(locationResult: LocationResult?) but the results tick in fine, and the position seems to be correct enough.

Can someone tell me if I can simply disregard the isLocationAvailable = false and just use the location results as they are, without taking any risks of getting false readings or or low accuracy or such?

I've tried with different settings for the LocationRequest, and there's no issue with any of them - except that the availability still gets called with false. The results themselves are fine.

Permissions are in place fair and square, I've also tried with ACCESS_FINE_LOCATION only, ACCESS_COARSE_LOCATION only and both on. Location are enabled on the devices.

Did something change about the inner workings of the FusedLocation system in the last few weeks? It's worked perfectly for years now?

Code:

var locationRequest: LocationRequest = LocationRequest.create().apply {
        interval = 10000
        fastestInterval = 5000
        priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY 
    }

When initializing and starting the location updates i use the following snip:

val locationClient = LocationServices.getFusedLocationProviderClient(this)
val builder = LocationSettingsRequest.Builder().addLocationRequest(locationRequest)
val client: SettingsClient = LocationServices.getSettingsClient(this)
val task: Task<LocationSettingsResponse> = client.checkLocationSettings(builder.build())
task.addOnSuccessListener { locationSettingsResponse ->
    locationClient?.requestLocationUpdates(locationRequest, locationCallback, null)
}

And with this LocationCallback:

val locationCallback = object : LocationCallback() {
    override fun onLocationResult(locationResult: LocationResult?) {
        locationResult ?: return
        if (locationResult.locations.isNotEmpty()) {
            val location = locationResult.locations[0]
        }
    }
    override fun onLocationAvailability(availability: LocationAvailability?) {
         availability?.isLocationAvailable          <-- This is always false!
    }
}

Solution

  • This issue is caused by new Google Play services update (version 21.30.16).

    See: https://issuetracker.google.com/issues/198176818

    As per Sep 9, 2021 they say:

    We have temporarily rolled back some of the logic around isLocationAvailable() and you should note behavior returning to normal over then next 24 hours or so.