LocationRequestCompat.Builder

Added in 1.7.0

public final class LocationRequestCompat.Builder


A builder class for LocationRequestCompat.

Summary

Public constructors

Builder(long intervalMillis)

Creates a new Builder with the given interval.

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

Public methods

@NonNull LocationRequestCompat

Builds a location request from this builder.

@NonNull 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).

@NonNull LocationRequestCompat.Builder
setDurationMillis(@IntRange(from = 1) long durationMillis)

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

@NonNull LocationRequestCompat.Builder
setIntervalMillis(@IntRange(from = 0) long intervalMillis)

Sets the request interval.

@NonNull LocationRequestCompat.Builder
setMaxUpdateDelayMillis(@IntRange(from = 0) long maxUpdateDelayMillis)

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

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

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

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

Sets the minimum update distance between location updates.

@NonNull LocationRequestCompat.Builder
setMinUpdateIntervalMillis(
    @IntRange(from = 0) long minUpdateIntervalMillis
)

Sets an explicit minimum update interval.

@NonNull LocationRequestCompat.Builder
setQuality(int quality)

Sets the request quality.

Public constructors

Builder

Added in 1.7.0
public Builder(long intervalMillis)

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
public Builder(@NonNull LocationRequestCompat locationRequest)

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

Public methods

build

Added in 1.7.0
public @NonNull LocationRequestCompat build()

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
public @NonNull LocationRequestCompat.Builder clearMinUpdateIntervalMillis()

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
public @NonNull LocationRequestCompat.Builder setDurationMillis(@IntRange(from = 1) long durationMillis)

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
public @NonNull LocationRequestCompat.Builder setIntervalMillis(@IntRange(from = 0) long intervalMillis)

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
public @NonNull LocationRequestCompat.Builder setMaxUpdateDelayMillis(@IntRange(from = 0) long maxUpdateDelayMillis)

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
public @NonNull LocationRequestCompat.Builder setMaxUpdates(@IntRange(from = 1, to = Integer.MAX_VALUE) int maxUpdates)

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
public @NonNull LocationRequestCompat.Builder setMinUpdateDistanceMeters(
    @FloatRange(from = 0, to = Float.MAX_VALUE) float minUpdateDistanceMeters
)

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
public @NonNull LocationRequestCompat.Builder setMinUpdateIntervalMillis(
    @IntRange(from = 0) long minUpdateIntervalMillis
)

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
public @NonNull LocationRequestCompat.Builder setQuality(int quality)

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.