LocationRequestCompat.Builder

public static final class LocationRequestCompat.Builder
extends Object

java.lang.Object
   ↳ androidx.core.location.LocationRequestCompat.Builder


A builder class for LocationRequestCompat.

Summary

Public constructors

Builder(long intervalMillis)

Creates a new Builder with the given interval.

Builder(LocationRequestCompat locationRequest)

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

Public methods

LocationRequestCompat build()

Builds a location request from this builder.

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

LocationRequestCompat.Builder setDurationMillis(long durationMillis)

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

LocationRequestCompat.Builder setIntervalMillis(long intervalMillis)

Sets the request interval.

LocationRequestCompat.Builder setMaxUpdateDelayMillis(long maxUpdateDelayMillis)

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

LocationRequestCompat.Builder setMaxUpdates(int maxUpdates)

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

LocationRequestCompat.Builder setMinUpdateDistanceMeters(float minUpdateDistanceMeters)

Sets the minimum update distance between location updates.

LocationRequestCompat.Builder setMinUpdateIntervalMillis(long minUpdateIntervalMillis)

Sets an explicit minimum update interval.

LocationRequestCompat.Builder setQuality(int quality)

Sets the request quality.

Inherited methods

Public constructors

Builder

public Builder (long intervalMillis)

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

Parameters
intervalMillis long

Builder

public Builder (LocationRequestCompat locationRequest)

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

Parameters
locationRequest LocationRequestCompat

Public methods

build

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

Returns
LocationRequestCompat

clearMinUpdateIntervalMillis

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

Returns
LocationRequestCompat.Builder

setDurationMillis

public LocationRequestCompat.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.

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

Parameters
durationMillis long

Value is 1 or greater.

Returns
LocationRequestCompat.Builder

setIntervalMillis

public LocationRequestCompat.Builder setIntervalMillis (long intervalMillis)

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

Note: On platforms below Android 12, using the LocationRequestCompat.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.

Parameters
intervalMillis long

Returns
LocationRequestCompat.Builder

setMaxUpdateDelayMillis

public LocationRequestCompat.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

Returns
LocationRequestCompat.Builder

setMaxUpdates

public LocationRequestCompat.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