LocationRequestCompat

Added in 1.7.0

public final class LocationRequestCompat


Compatibility version of LocationRequest.

Summary

Nested types

A builder class for LocationRequestCompat.

Constants

static final long
PASSIVE_INTERVAL = 9223372036854775807

Represents a passive only request.

static final int

A quality constant indicating a location provider may choose to satisfy this request by equally balancing power and accuracy constraints.

static final int

A quality constant indicating a location provider may choose to satisfy this request by providing very accurate locations at the expense of potentially increased power usage.

static final int

A quality constant indicating a location provider may choose to satisfy this request by providing less accurate locations in order to save power.

Public methods

boolean
@IntRange(from = 1) long

Returns the duration for which location will be provided before the request is automatically removed.

@IntRange(from = 0) long

Returns the desired interval of location updates, or PASSIVE_INTERVAL if this is a passive, no power request.

@IntRange(from = 0) long

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

@IntRange(from = 1, to = Integer.MAX_VALUE) int

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

@FloatRange(from = 0, to = Float.MAX_VALUE) float

Returns the minimum distance between location updates.

@IntRange(from = 0) long

Returns the minimum update interval.

int

Returns the quality hint for this location request.

int
@NonNull LocationRequest

Converts an instance to an equivalent LocationRequest.

@Nullable LocationRequest

Converts an instance to an equivalent LocationRequest, with the provider field of the resulting LocationRequest set to the provider argument provided to this method.

@NonNull String

Constants

PASSIVE_INTERVAL

Added in 1.7.0
public static final long PASSIVE_INTERVAL = 9223372036854775807

Represents a passive only request. Such a request will not trigger any active locations or power usage itself, but may receive locations generated in response to other requests.

QUALITY_BALANCED_POWER_ACCURACY

Added in 1.7.0
public static final int QUALITY_BALANCED_POWER_ACCURACY = 102

A quality constant indicating a location provider may choose to satisfy this request by equally balancing power and accuracy constraints. Each location provider may interpret this field differently, but location providers will generally use their default behavior when this flag is present.

QUALITY_HIGH_ACCURACY

Added in 1.7.0
public static final int QUALITY_HIGH_ACCURACY = 100

A quality constant indicating a location provider may choose to satisfy this request by providing very accurate locations at the expense of potentially increased power usage. Each location provider may interpret this field differently, but as an example, the network provider may choose to return only wifi based locations rather than cell based locations in order to have greater accuracy when this flag is present.

QUALITY_LOW_POWER

Added in 1.7.0
public static final int QUALITY_LOW_POWER = 104

A quality constant indicating a location provider may choose to satisfy this request by providing less accurate locations in order to save power. Each location provider may interpret this field differently, but as an example, the network provider may choose to return cell based locations rather than wifi based locations in order to save power when this flag is present.

Public methods

equals

public boolean equals(Object o)

getDurationMillis

Added in 1.7.0
public @IntRange(from = 1) long getDurationMillis()

Returns the duration for which location will be provided before the request is automatically removed. A duration of Long.MAX_VALUE represents an unlimited duration.

Returns
@IntRange(from = 1) long

the duration for which location will be provided

getIntervalMillis

Added in 1.7.0
public @IntRange(from = 0) long getIntervalMillis()

Returns the desired interval of location updates, or PASSIVE_INTERVAL if this is a passive, no power request. A passive 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 getMinUpdateIntervalMillis for the behavior in that case.

getMaxUpdateDelayMillis

Added in 1.7.0
public @IntRange(from = 0) long getMaxUpdateDelayMillis()

Returns 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. The maximum batch size is the maximum update delay divided by the interval. Not all devices or location providers support batching, and use of this parameter does not guarantee that the client will see batched results, or that batched results will always be of the maximum size. When available, batching can provide substantial power savings to the device, and clients are encouraged to take advantage where appropriate for the use case.

Returns
@IntRange(from = 0) long

the maximum time by which a location update may be delayed

getMaxUpdates

Added in 1.7.0
public @IntRange(from = 1, to = Integer.MAX_VALUE) int getMaxUpdates()

Returns the maximum number of location updates for this request before the request is automatically removed. A max updates value of Integer.MAX_VALUE represents an unlimited number of updates.

getMinUpdateDistanceMeters

Added in 1.7.0
public @FloatRange(from = 0, to = Float.MAX_VALUE) float getMinUpdateDistanceMeters()

Returns the minimum 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. A value of 0 meters implies that no location update will ever be rejected due to failing this constraint.

Returns
@FloatRange(from = 0, to = Float.MAX_VALUE) float

the minimum distance between location updates

getMinUpdateIntervalMillis

Added in 1.7.0
public @IntRange(from = 0) long getMinUpdateIntervalMillis()

Returns the minimum update interval. If location updates are available faster than the request interval then locations will only be updated if the minimum update interval has expired since the last location update.

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.

Returns
@IntRange(from = 0) long

the minimum update interval

getQuality

Added in 1.7.0
public int getQuality()

Returns the quality hint for this location request. The quality hint informs the provider how it should attempt to manage any accuracy vs power tradeoffs while attempting to satisfy this location request.

hashCode

public int hashCode()

toLocationRequest

Added in 1.7.0
@RequiresApi(value = 31)
public @NonNull LocationRequest toLocationRequest()

Converts an instance to an equivalent LocationRequest.

Returns
@NonNull LocationRequest

platform class object

See also
LocationRequest

toLocationRequest

Added in 1.7.0
public @Nullable LocationRequest toLocationRequest(@NonNull String provider)

Converts an instance to an equivalent LocationRequest, with the provider field of the resulting LocationRequest set to the provider argument provided to this method.

May return null on some SDKs if various reflective operations fail. This should only occur on non-standard Android devices, and thus should be rare.

Returns
@Nullable LocationRequest

platform class object

See also
LocationRequest

toString

public @NonNull String toString()