Added in API level 31

Builder

class Builder
kotlin.Any
   ↳ android.location.LocationRequest.Builder

A builder class for LocationRequest.

Summary

Public constructors
Builder(intervalMillis: Long)

Creates a new Builder with the given interval.

Builder(locationRequest: LocationRequest)

Creates a new Builder with all parameters copied from the given location request.

Public methods
LocationRequest

Builds a location request from this builder.

LocationRequest.Builder

Clears an explicitly set minimum update interval and reverts to an implicit minimum update interval (ie, the minimum update interval is some sensible default between 0 and the interval).

LocationRequest.Builder
setDurationMillis(durationMillis: Long)

Sets the duration this request will continue before being automatically removed.

LocationRequest.Builder
setIntervalMillis(intervalMillis: Long)

Sets the request interval.

LocationRequest.Builder
setMaxUpdateDelayMillis(maxUpdateDelayMillis: Long)

Sets the maximum time any location update may be delayed, and thus grouped with following updates to enable location batching.

LocationRequest.Builder
setMaxUpdates(maxUpdates: Int)

Sets the maximum number of location updates for this request before this request is automatically removed.

LocationRequest.Builder
setMinUpdateDistanceMeters(minUpdateDistanceMeters: Float)

Sets the minimum update distance between location updates.

LocationRequest.Builder
setMinUpdateIntervalMillis(minUpdateIntervalMillis: Long)

Sets an explicit minimum update interval.

LocationRequest.Builder
setQuality(quality: Int)

Sets the request quality.

Public constructors

Builder

Added in API level 31
Builder(intervalMillis: Long)

Creates a new Builder with the given interval. See setIntervalMillis(long) for more information on the interval.

Builder

Added in API level 31
Builder(locationRequest: LocationRequest)

Creates a new Builder with all parameters copied from the given location request.

Parameters
locationRequest LocationRequest: This value cannot be null.

Public methods

build

Added in API level 31
fun build(): LocationRequest

Builds a location request from this builder. If an explicit minimum update interval is set, the minimum update interval of the location request will be the minimum of the interval and minimum update interval.

If building a passive request then you must have set an explicit minimum update interval.

Return
LocationRequest a new location request This value cannot be null.
Exceptions
java.lang.IllegalStateException if building a passive request with no explicit minimum update interval set

clearMinUpdateIntervalMillis

Added in API level 31
fun clearMinUpdateIntervalMillis(): LocationRequest.Builder

Clears an explicitly set minimum update interval and reverts to an implicit minimum update interval (ie, the minimum update interval is some sensible default between 0 and the interval).

Return
LocationRequest.Builder This value cannot be null.

setDurationMillis

Added in API level 31
fun setDurationMillis(durationMillis: Long): LocationRequest.Builder

Sets the duration this request will continue before being automatically removed. Defaults to Long.MAX_VALUE, which represents an unlimited duration.

Parameters
durationMillis Long: Value is 1 or greater
Return
LocationRequest.Builder This value cannot be null.

setIntervalMillis

Added in API level 31
fun setIntervalMillis(intervalMillis: Long): LocationRequest.Builder

Sets the request interval. The request interval may be set to PASSIVE_INTERVAL which indicates this request will not actively generate location updates (and thus will not be power blamed for location), but may receive location updates generated as a result of other location requests. A passive request must always have an explicit minimum update interval set.

Locations may be available at a faster interval than specified here, see setMinUpdateIntervalMillis(long) for the behavior in that case.

Parameters
intervalMillis Long: Value is 0 or greater
Return
LocationRequest.Builder This value cannot be null.

setMaxUpdateDelayMillis

Added in API level 31
fun setMaxUpdateDelayMillis(maxUpdateDelayMillis: Long): LocationRequest.Builder

Sets the maximum time any location update may be delayed, and thus grouped with following updates to enable location batching. If the maximum update delay is equal to or greater than twice the interval, then location providers may provide batched results. Defaults to 0, which represents no batching allowed.

Parameters
maxUpdateDelayMillis Long: Value is 0 or greater
Return
LocationRequest.Builder This value cannot be null.

setMaxUpdates

Added in API level 31
fun setMaxUpdates(maxUpdates: Int): LocationRequest.Builder

Sets the maximum number of location updates for this request before this request is automatically removed. Defaults to Integer.MAX_VALUE, which represents an unlimited number of updates.

Parameters
maxUpdates Int: Value is between 1 and Integer.MAX_VALUE inclusive
Return
LocationRequest.Builder This value cannot be null.

setMinUpdateDistanceMeters

Added in API level 31
fun setMinUpdateDistanceMeters(minUpdateDistanceMeters: Float): LocationRequest.Builder

Sets the minimum update distance between location updates. If a potential location update is closer to the last location update than the minimum update distance, then the potential location update will not occur. Defaults to 0, which represents no minimum update distance.

Parameters
minUpdateDistanceMeters Float: Value is between 0 and Float.MAX_VALUE inclusive
Return
LocationRequest.Builder This value cannot be null.

setMinUpdateIntervalMillis

Added in API level 31
fun setMinUpdateIntervalMillis(minUpdateIntervalMillis: Long): LocationRequest.Builder

Sets an explicit minimum update interval. If location updates are available faster than the request interval then an update will only occur if the minimum update interval has expired since the last location update. Defaults to no explicit minimum update interval set, which means some sensible default between 0 and the interval will be chosen. The exact value is not specified at the moment. If an exact known value is required, clients should set an explicit value themselves.

Note: Some allowance for jitter is already built into the minimum update interval, so you need not worry about updates blocked simply because they arrived a fraction of a second earlier than expected.

Note: When build() is invoked, the minimum of the interval and the minimum update interval will be used as the minimum update interval of the built request.

Parameters
minUpdateIntervalMillis Long: Value is 0 or greater
Return
LocationRequest.Builder This value cannot be null.

setQuality

Added in API level 31
fun setQuality(quality: Int): LocationRequest.Builder

Sets the request quality. The quality is a hint to providers on how they should weigh power vs accuracy tradeoffs. High accuracy locations may cost more power to produce, and lower accuracy locations may cost less power to produce. Defaults to QUALITY_BALANCED_POWER_ACCURACY.

Parameters
quality Int: Value is android.location.LocationRequest#QUALITY_LOW_POWER, android.location.LocationRequest#QUALITY_BALANCED_POWER_ACCURACY, or android.location.LocationRequest#QUALITY_HIGH_ACCURACY
Return
LocationRequest.Builder This value cannot be null.