Yes, the LocationRequest constructor is deprecated. You can use its static method LocationRequest.create() to create a location request.
Kotlin:
locationRequest = LocationRequest.create().apply {
interval = 100
fastestInterval = 50
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
maxWaitTime = 100
}
Java:
locationRequest = LocationRequest.create()
.setInterval(100)
.setFastestInterval(3000)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setMaxWaitTime(100);
Update
As @Shimon pointed out LocationRequest.PRIORITY_HIGH_ACCURACY is now deprecated, so instead use Priority.PRIORITY_HIGH_ACCURACY
Answer from Kunu on Stack OverflowVideos
Yes, the LocationRequest constructor is deprecated. You can use its static method LocationRequest.create() to create a location request.
Kotlin:
locationRequest = LocationRequest.create().apply {
interval = 100
fastestInterval = 50
priority = LocationRequest.PRIORITY_HIGH_ACCURACY
maxWaitTime = 100
}
Java:
locationRequest = LocationRequest.create()
.setInterval(100)
.setFastestInterval(3000)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setMaxWaitTime(100);
Update
As @Shimon pointed out LocationRequest.PRIORITY_HIGH_ACCURACY is now deprecated, so instead use Priority.PRIORITY_HIGH_ACCURACY
LocationRequest.create().apply{ ... } is now also deprecated.
Please use LocationRequest.Builder() instead. I.E. like this:
(locationInterval, locationFastestInterval and locationMaxWaitTime corresponds to the values used before when using create())
locationRequest = LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, locationInterval)
.setWaitForAccurateLocation(false)
.setMinUpdateIntervalMillis(locationFastestInterval)
.setMaxUpdateDelayMillis(locationMaxWaitTime)
.build()
Please read more here: https://developer.android.com/reference/android/location/LocationRequest.Builder
and here: https://developers.google.com/android/reference/com/google/android/gms/location/LocationRequest.Builder
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()
LocationRequest locationRequest =
new LocationRequest.Builder(
LocationRequest.PRIORITY_HIGH_ACCURACY,
10000
).build();
locationRequest.setFastestInterval(5000);
locationRequest = new LocationRequest.Builder(Priority.PRIORITY_HIGH_ACCURACY, 100)
.setIntervalMillis(INTERVAL_MILLIS) // Sets the interval for location updates
.setMinUpdateIntervalMillis(INTERVAL_MILLIS/2) // Sets the fastest allowed interval of location updates.
.setWaitForAccurateLocation(false) // Want Accurate location updates make it true or you get approximate updates
.setMaxUpdateDelayMillis(100) // Sets the longest a location update may be delayed.
.build();