Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!
    }
}
like image 400
Christian Avatar asked Sep 06 '21 15:09

Christian


People also ask

Why fusedlocationclient doesn’t return location?

If user disables location in quick menu on top of phone or in settings and tries to enter app, it gets message that location is disabled and exits. After that if user tries to turn on location and enter app FusedLocationClient gets stuck and doesn’t return location at all.

How to request for fusedlocationproviderapi’s quality of service?

We will use LocationRequest to request the FusedLocationProviderApi’s quality of service for location updates. There are also different methods and approaches which can be extended which are viz: setFastestInterval (long millis): This method is used to provide the quickest interval for a location update.

How to use the Fused Location API in Android?

To utilize the Fused Location API, you must first add the location dependency. So, add the following dependency to your app’s build.gradle file: In order to use location services, you must add location permission to the AndroidManifest.xml file. Depending on your needs, you may use ACCESS COARSE LOCATION or ACCESS FINE LOCATION:

How accurate is fused location?

We're using Fused Location as well, and discard those locations that older than 20 seconds and accuracy less than 200 meters. But still, it returns a new location with newest fetched and very high accuracy, but totally wrong location (sometimes 100 meters away sometimes a few km away.)


1 Answers

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.

like image 127
Alex Balan Avatar answered Sep 22 '22 15:09

Alex Balan