public final class

LocationRequestCompat.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.core.location.LocationRequestCompat.Builder

Overview

A builder class for LocationRequestCompat.

Summary

Constructors
publicBuilder(LocationRequestCompat locationRequest)

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

publicBuilder(long intervalMillis)

Creates a new Builder with the given interval.

Methods
public LocationRequestCompatbuild()

Builds a location request from this builder.

public LocationRequestCompat.BuilderclearMinUpdateIntervalMillis()

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

public LocationRequestCompat.BuildersetDurationMillis(long durationMillis)

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

public LocationRequestCompat.BuildersetIntervalMillis(long intervalMillis)

Sets the request interval.

public LocationRequestCompat.BuildersetMaxUpdateDelayMillis(long maxUpdateDelayMillis)

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

public LocationRequestCompat.BuildersetMaxUpdates(int maxUpdates)

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

public LocationRequestCompat.BuildersetMinUpdateDistanceMeters(float minUpdateDistanceMeters)

Sets the minimum update distance between location updates.

public LocationRequestCompat.BuildersetMinUpdateIntervalMillis(long minUpdateIntervalMillis)

Sets an explicit minimum update interval.

public LocationRequestCompat.BuildersetQuality(int quality)

Sets the request quality.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(long intervalMillis)

Creates a new Builder with the given interval. See LocationRequestCompat.Builder.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 .

public Builder(LocationRequestCompat locationRequest)

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

Methods

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

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

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.

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.

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

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

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

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.

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.