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()
)
You can use it like this
val locationRequest = LocationRequest.create().apply {
interval = LOCATION_UPDATE_INTERVAL
fastestInterval = LOCATION_FASTEST_INTERVAL
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
}
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With