Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(geolocation): add minimumUpdateInterval parameter for startWatch #2271

Closed
wants to merge 7 commits into from
11 changes: 6 additions & 5 deletions geolocation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,12 @@ Request location permissions. Will throw if system location services are disabl

#### PositionOptions

| Prop | Type | Description | Default | Since |
| ------------------------ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
| **`enableHighAccuracy`** | <code>boolean</code> | High accuracy mode (such as GPS, if available) On Android 12+ devices it will be ignored if users didn't grant ACCESS_FINE_LOCATION permissions (can be checked with location alias). | <code>false</code> | 1.0.0 |
| **`timeout`** | <code>number</code> | The maximum wait time in milliseconds for location updates. In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition. | <code>10000</code> | 1.0.0 |
| **`maximumAge`** | <code>number</code> | The maximum age in milliseconds of a possible cached position that is acceptable to return | <code>0</code> | 1.0.0 |
| Prop | Type | Description | Default | Since |
| --------------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
| **`enableHighAccuracy`** | <code>boolean</code> | High accuracy mode (such as GPS, if available) On Android 12+ devices it will be ignored if users didn't grant ACCESS_FINE_LOCATION permissions (can be checked with location alias). | <code>false</code> | 1.0.0 |
| **`timeout`** | <code>number</code> | The maximum wait time in milliseconds for location updates. In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition. | <code>10000</code> | 1.0.0 |
| **`maximumAge`** | <code>number</code> | The maximum age in milliseconds of a possible cached position that is acceptable to return | <code>0</code> | 1.0.0 |
| **`minimumUpdateInterval`** | <code>number</code> | The minumum update interval for location updates. If location updates are available faster than this interval then an update will only occur if the minimum update interval has expired since the last location update. | <code>5000</code> | 6.1.0 |


#### ClearWatchOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void sendLocation(boolean enableHighAccuracy, final LocationResultCallbac
}

@SuppressWarnings("MissingPermission")
public void requestLocationUpdates(boolean enableHighAccuracy, int timeout, final LocationResultCallback resultCallback) {
public void requestLocationUpdates(boolean enableHighAccuracy, int timeout, int minUpdateInterval, final LocationResultCallback resultCallback) {
int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
if (resultCode == ConnectionResult.SUCCESS) {
clearLocationUpdates();
Expand All @@ -87,7 +87,7 @@ public void requestLocationUpdates(boolean enableHighAccuracy, int timeout, fina

LocationRequest locationRequest = new LocationRequest.Builder(10000)
.setMaxUpdateDelayMillis(timeout)
.setMinUpdateIntervalMillis(5000)
.setMinUpdateIntervalMillis(minUpdateInterval)
.setPriority(priority)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@ public void error(String message) {
@SuppressWarnings("MissingPermission")
private void startWatch(final PluginCall call) {
int timeout = call.getInt("timeout", 10000);
int minUpdateInterval = call.getInt("minimumUpdateInterval", 5000);

implementation.requestLocationUpdates(
isHighAccuracy(call),
timeout,
minUpdateInterval,
new LocationResultCallback() {
@Override
public void success(Location location) {
Expand Down
11 changes: 11 additions & 0 deletions geolocation/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ export interface PositionOptions {
* @since 1.0.0
*/
maximumAge?: number;

/**
* The minumum update interval for location updates.
*
* If location updates are available faster than this interval then an update
* will only occur if the minimum update interval has expired since the last location update.
*
* @default 5000
* @since 6.1.0
*/
minimumUpdateInterval?: number;
}

export type WatchPositionCallback = (
Expand Down
1 change: 1 addition & 0 deletions geolocation/src/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class GeolocationWeb extends WebPlugin implements GeolocationPlugin {
enableHighAccuracy: false,
timeout: 10000,
maximumAge: 0,
minimumUpdateInterval: 5000,
...options,
},
);
Expand Down
Loading