LocationRequestCompat
public final class LocationRequestCompat
Compatibility version of LocationRequest.
Summary
Nested types |
|---|
public final class LocationRequestCompat.BuilderA builder class for |
Constants |
|
|---|---|
static final long |
PASSIVE_INTERVAL = 9223372036854775807Represents 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 |
QUALITY_HIGH_ACCURACY = 100A 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 |
QUALITY_LOW_POWER = 104A 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 |
@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 |
hashCode() |
@NonNull LocationRequest |
@RequiresApi(value = 31)Converts an instance to an equivalent |
@Nullable LocationRequest |
toLocationRequest(@NonNull String provider)Converts an instance to an equivalent |
@NonNull String |
toString() |
Constants
PASSIVE_INTERVAL
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.
| See also | |
|---|---|
getIntervalMillis |
QUALITY_BALANCED_POWER_ACCURACY
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
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
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
getDurationMillis
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
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
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 |
| See also | |
|---|---|
onLocationChanged |
getMaxUpdates
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
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
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
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.
toLocationRequest
@RequiresApi(value = 31)
public @NonNull LocationRequest toLocationRequest()
Converts an instance to an equivalent LocationRequest.
| Returns | |
|---|---|
@NonNull LocationRequest |
platform class object |
| See also | |
|---|---|
LocationRequest |
toLocationRequest
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 |