diff --git a/geolocation/README.md b/geolocation/README.md index 2c2f86313..57113e7b7 100644 --- a/geolocation/README.md +++ b/geolocation/README.md @@ -171,11 +171,12 @@ Request location permissions. Will throw if system location services are disabl #### PositionOptions -| Prop | Type | Description | Default | Since | -| ------------------------ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- | -| **`enableHighAccuracy`** | boolean | 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). | false | 1.0.0 | -| **`timeout`** | number | The maximum wait time in milliseconds for location updates. In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition. | 10000 | 1.0.0 | -| **`maximumAge`** | number | The maximum age in milliseconds of a possible cached position that is acceptable to return | 0 | 1.0.0 | +| Prop | Type | Description | Default | Since | +| --------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- | +| **`enableHighAccuracy`** | boolean | 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). | false | 1.0.0 | +| **`timeout`** | number | The maximum wait time in milliseconds for location updates. In Android, since version 4.0.0 of the plugin, timeout gets ignored for getCurrentPosition. | 10000 | 1.0.0 | +| **`maximumAge`** | number | The maximum age in milliseconds of a possible cached position that is acceptable to return | 0 | 1.0.0 | +| **`minimumUpdateInterval`** | 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. This parameter is only available for Android. It has no effect on iOS or Web platforms. | 5000 | 6.1.0 | #### ClearWatchOptions diff --git a/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java b/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java index 41b8af269..e5263a0a2 100644 --- a/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java +++ b/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java @@ -68,7 +68,12 @@ 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(); @@ -87,7 +92,7 @@ public void requestLocationUpdates(boolean enableHighAccuracy, int timeout, fina LocationRequest locationRequest = new LocationRequest.Builder(10000) .setMaxUpdateDelayMillis(timeout) - .setMinUpdateIntervalMillis(5000) + .setMinUpdateIntervalMillis(minUpdateInterval) .setPriority(priority) .build(); diff --git a/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/GeolocationPlugin.java b/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/GeolocationPlugin.java index 84514a682..d198c675b 100644 --- a/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/GeolocationPlugin.java +++ b/geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/GeolocationPlugin.java @@ -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) { diff --git a/geolocation/src/definitions.ts b/geolocation/src/definitions.ts index 94fd9b61f..9e6239e1d 100644 --- a/geolocation/src/definitions.ts +++ b/geolocation/src/definitions.ts @@ -180,6 +180,19 @@ 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. + * + * This parameter is only available for Android. It has no effect on iOS or Web platforms. + * + * @default 5000 + * @since 6.1.0 + */ + minimumUpdateInterval?: number; } export type WatchPositionCallback = ( diff --git a/geolocation/src/web.ts b/geolocation/src/web.ts index 6830085de..5288ff9c0 100644 --- a/geolocation/src/web.ts +++ b/geolocation/src/web.ts @@ -44,6 +44,7 @@ export class GeolocationWeb extends WebPlugin implements GeolocationPlugin { enableHighAccuracy: false, timeout: 10000, maximumAge: 0, + minimumUpdateInterval: 5000, ...options, }, );