Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LocationRequest (FusedLocationProviderClient) - Deprecated

LocationRequest is now deprecated? What is the replacement for it?

I was using it and recently got a deprecation message. What should I do now:

val locationRequest = LocationRequest().apply {
            interval = LOCATION_UPDATE_INTERVAL
            fastestInterval = LOCATION_FASTEST_INTERVAL
            priority = LocationRequest.PRIORITY_HIGH_ACCURACY
        }
        fusedLocationProviderClient.requestLocationUpdates(
            locationRequest,
            locationCallback,
            Looper.getMainLooper()
        )
like image 209
Hassa Avatar asked Oct 18 '25 19:10

Hassa


2 Answers

You can use it like this

val locationRequest = LocationRequest.create().apply {
        interval = LOCATION_UPDATE_INTERVAL
        fastestInterval = LOCATION_FASTEST_INTERVAL
        priority = LocationRequest.PRIORITY_HIGH_ACCURACY
    }
like image 57
Divij Gupta Avatar answered Oct 20 '25 09:10

Divij Gupta


Location services were updated to version 21.0.0, and the LocationRequest.create was deprecated with the new update.

Here is how to change LocationRequest.create to recommended LocationRequest.Builder:

   fun createLocationRequest() = LocationRequest.Builder(
        Priority.PRIORITY_HIGH_ACCURACY, TimeUnit.MINUTES.toMillis(5)
    ).apply {
        setGranularity(Granularity.GRANULARITY_PERMISSION_LEVEL)
        setDurationMillis(TimeUnit.MINUTES.toMillis(5))
        setWaitForAccurateLocation(true)
        setMaxUpdates(1)
    }.build()
like image 33
Shahab Saalami Avatar answered Oct 20 '25 09:10

Shahab Saalami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!