LocationRequestCompat.Builder

Added in 1.7.0

class LocationRequestCompat.Builder


A builder class for LocationRequestCompat.

Summary

Public constructors

Builder(intervalMillis: Long)

Creates a new Builder with the given interval.

Builder(locationRequest: LocationRequestCompat)

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

Public functions

LocationRequestCompat

Builds a location request from this builder.

LocationRequestCompat.Builder

Clears an explicitly set minimum update interval and reverts to an implicit minimum update interval (ie, the minimum update interval is the same value as the interval).

LocationRequestCompat.Builder
setDurationMillis(durationMillis: @IntRange(from = 1) Long)

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

LocationRequestCompat.Builder
setIntervalMillis(intervalMillis: @IntRange(from = 0) Long)

Sets the request interval.

LocationRequestCompat.Builder
setMaxUpdateDelayMillis(maxUpdateDelayMillis: @IntRange(from = 0) Long)

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

LocationRequestCompat.Builder
setMaxUpdates(maxUpdates: @IntRange(from = 1, to = Integer.MAX_VALUE) Int)

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

LocationRequestCompat.Builder
setMinUpdateDistanceMeters(
    minUpdateDistanceMeters: @FloatRange(from = 0, to = Float.MAX_VALUE) Float
)

Sets the minimum update distance between location updates.

LocationRequestCompat.Builder
setMinUpdateIntervalMillis(
    minUpdateIntervalMillis: @IntRange(from = 0) Long
)

Sets an explicit minimum update interval.

LocationRequestCompat.Builder
setQuality(quality: Int)

Sets the request quality.

Public constructors

Builder

Added in 1.7.0
Builder(intervalMillis: Long)

Creates a new Builder with the given interval. See setIntervalMillis for more information on the interval. Note that the defaults for various Builder parameters may be different from the defaults for the framework LocationRequest.

Builder

Added in 1.7.0
Builder(locationRequest: LocationRequestCompat)

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

Public functions

build

Added in 1.7.0
fun build(): LocationRequestCompat

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.

clearMinUpdateIntervalMillis

Added in 1.7.0
fun clearMinUpdateIntervalMillis(): LocationRequestCompat.Builder

Clears an explicitly set minimum update interval and reverts to an implicit minimum update interval (ie, the minimum update interval is the same value as the interval).

setDurationMillis

Added in 1.7.0
fun setDurationMillis(durationMillis: @IntRange(from = 1) Long): LocationRequestCompat.Builder

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

Note: This parameter will be ignored on platforms below Android Kitkat, and the request will not be removed after the duration expires.

setIntervalMillis

Added in 1.7.0
fun setIntervalMillis(intervalMillis: @IntRange(from = 0) Long): LocationRequestCompat.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 for the behavior in that case.

Note: On platforms below Android 12, using the PASSIVE_INTERVAL will not result in a truly passive request, but a request with an extremely long interval. In most cases, this is effectively the same as a passive request, but this may occasionally result in an initial location calculation for which the client will be blamed.

setMaxUpdateDelayMillis

Added in 1.7.0
fun setMaxUpdateDelayMillis(maxUpdateDelayMillis: @IntRange(from = 0) Long): LocationRequestCompat.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.

setMaxUpdates

Added in 1.7.0
fun setMaxUpdates(maxUpdates: @IntRange(from = 1, to = Integer.MAX_VALUE) Int): LocationRequestCompat.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.

setMinUpdateDistanceMeters

Added in 1.7.0
fun setMinUpdateDistanceMeters(
    minUpdateDistanceMeters: @FloatRange(from = 0, to = Float.MAX_VALUE) Float
): LocationRequestCompat.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.

setMinUpdateIntervalMillis

Added in 1.7.0
fun setMinUpdateIntervalMillis(
    minUpdateIntervalMillis: @IntRange(from = 0) Long
): LocationRequestCompat.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 the minimum update interval is the same as the interval.

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.

setQuality

Added in 1.7.0
fun setQuality(quality: Int): LocationRequestCompat.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.