# LocationRequestCompat

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/location/LocationRequestCompat.java+class:androidx.core.location.LocationRequestCompat) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

*** ** * ** ***


```
public final class LocationRequestCompat
```

<br />

*** ** * ** ***

Compatibility version of `https://developer.android.com/reference/android/location/LocationRequest.html`.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/core/location/LocationRequestCompat.Builder` A builder class for `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat`. |

| ### Constants |
|---|---|
| `static final long` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#PASSIVE_INTERVAL() = 9223372036854775807` Represents a passive only request. |
| `static final int` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#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. |
| `static final int` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#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. |
| `static final int` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#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. |

| ### Public methods |
|---|---|
| `boolean` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object.html o)` |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) long` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#getDurationMillis()()` Returns the duration for which location will be provided before the request is automatically removed. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#getIntervalMillis()()` Returns the desired interval of location updates, or `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#PASSIVE_INTERVAL()` if this is a passive, no power request. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#getMaxUpdateDelayMillis()()` Returns the maximum time any location update may be delayed, and thus grouped with following updates to enable location batching. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1, to = https://developer.android.com/reference/java/lang/Integer.html#MAX_VALUE) int` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#getMaxUpdates()()` Returns the maximum number of location updates for this request before the request is automatically removed. |
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0, to = https://developer.android.com/reference/java/lang/Float.html#MAX_VALUE) float` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#getMinUpdateDistanceMeters()()` Returns the minimum distance between location updates. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#getMinUpdateIntervalMillis()()` Returns the minimum update interval. |
| `int` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#getQuality()()` Returns the quality hint for this location request. |
| `int` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#hashCode()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/location/LocationRequest.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 31) https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#toLocationRequest()()` Converts an instance to an equivalent `https://developer.android.com/reference/android/location/LocationRequest.html`. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/location/LocationRequest.html` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#toLocationRequest(java.lang.String)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html provider)` Converts an instance to an equivalent `https://developer.android.com/reference/android/location/LocationRequest.html`, with the provider field of the resulting LocationRequest set to the provider argument provided to this method. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#toString()()` |

## Constants

### PASSIVE_INTERVAL

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#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.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#getIntervalMillis()` |   |

### QUALITY_BALANCED_POWER_ACCURACY

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/jetpack/androidx/releases/core#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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 1) long` | the duration for which location will be provided |

### getIntervalMillis

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
public @IntRange(from = 0) long getIntervalMillis()
```

Returns the desired interval of location updates, or `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#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 `https://developer.android.com/reference/androidx/core/location/LocationRequestCompat#getMinUpdateIntervalMillis()` for the behavior in that case.

### getMaxUpdateDelayMillis

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long` | the maximum time by which a location update may be delayed |

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/core/location/LocationListenerCompat#onLocationChanged(java.util.List<android.location.Location>)` |   |

### getMaxUpdates

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/jetpack/androidx/releases/core#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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0, to = https://developer.android.com/reference/java/lang/Float.html#MAX_VALUE) float` | the minimum distance between location updates |

### getMinUpdateIntervalMillis

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0) long` | the minimum update interval |

### getQuality

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#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](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
@RequiresApi(value = 31)
public @NonNull LocationRequest toLocationRequest()
```

Converts an instance to an equivalent `https://developer.android.com/reference/android/location/LocationRequest.html`.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/location/LocationRequest.html` | platform class object |

| See also |
|---|---|
| `https://developer.android.com/reference/android/location/LocationRequest.html` |   |

### toLocationRequest

Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/core#1.7.0)

```
public @Nullable LocationRequest toLocationRequest(@NonNull String provider)
```

Converts an instance to an equivalent `https://developer.android.com/reference/android/location/LocationRequest.html`, 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 |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/location/LocationRequest.html` | platform class object |

| See also |
|---|---|
| `https://developer.android.com/reference/android/location/LocationRequest.html` |   |

### toString

```
public @NonNull String toString()
```