LocationRequest.Builder


public static final class LocationRequest.Builder
extends Object

java.lang.Object
   ↳ android.location.LocationRequest.Builder


A builder class for LocationRequest.

Summary

Public constructors

Builder(long intervalMillis)

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 build()

Builds a location request from this builder.

LocationRequest.Builder clearMinUpdateIntervalMillis()

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(long durationMillis)

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

LocationRequest.Builder setIntervalMillis(long intervalMillis)

Sets the request interval.

LocationRequest.Builder setMaxUpdateDelayMillis(long maxUpdateDelayMillis)

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

LocationRequest.Builder setMaxUpdates(int maxUpdates)

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

LocationRequest.Builder setMinUpdateDistanceMeters(float minUpdateDistanceMeters)

Sets the minimum update distance between location updates.

LocationRequest.Builder setMinUpdateIntervalMillis(long minUpdateIntervalMillis)

Sets an explicit minimum update interval.

LocationRequest.Builder setQuality(int quality)

Sets the request quality.

Inherited methods

Public constructors

Builder

Added in API level 31
public Builder (long intervalMillis)

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

Parameters
intervalMillis long

Builder

Added in API level 31
public 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
public LocationRequest 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.

Returns
LocationRequest a new location request This value cannot be null.

Throws
IllegalStateException if building a passive request with no explicit minimum update interval set

clearMinUpdateIntervalMillis

Added in API level 31
public LocationRequest.Builder clearMinUpdateIntervalMillis ()

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

Returns
LocationRequest.Builder This value cannot be null.

setDurationMillis

Added in API level 31
public LocationRequest.Builder setDurationMillis (long durationMillis)

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

Returns
LocationRequest.Builder This value cannot be null.

setIntervalMillis

Added in API level 31
public LocationRequest.Builder setIntervalMillis (long intervalMillis)

Sets the request interval. The request interval may be set to LocationRequest.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

Returns
LocationRequest.Builder This value cannot be null.

setMaxUpdateDelayMillis

Added in API level 31
public LocationRequest.Builder setMaxUpdateDelayMillis (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.

Parameters
maxUpdateDelayMillis long: Value is 0 or greater

Returns
LocationRequest.Builder This value cannot be null.

setMaxUpdates

Added in API level 31
public LocationRequest.Builder setMaxUpdates (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.

Parameters
maxUpdates int: Value is between 1 and Integer.MAX_VALUE inclusive

Returns
LocationRequest.Builder This value cannot be null.

setMinUpdateDistanceMeters

Added in API level 31
public LocationRequest.Builder setMinUpdateDistanceMeters (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.

Parameters
minUpdateDistanceMeters float: Value is between 0 and Float.MAX_VALUE inclusive

Returns
LocationRequest.Builder This value cannot be null.

setMinUpdateIntervalMillis

Added in API level 31
public LocationRequest.Builder setMinUpdateIntervalMillis (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 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

Returns
LocationRequest.Builder This value cannot be null.

setQuality

Added in API level 31
public LocationRequest.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 LocationRequest.QUALITY_BALANCED_POWER_ACCURACY.

Parameters
quality int: Value is LocationRequest.QUALITY_LOW_POWER, LocationRequest.QUALITY_BALANCED_POWER_ACCURACY, or LocationRequest.QUALITY_HIGH_ACCURACY

Returns
LocationRequest.Builder This value cannot be null.