Skip to content

Commit c6ddc53

Browse files
feat(geolocation): add minimumUpdateInterval parameter for startWatch (#2272)
1 parent 53acfab commit c6ddc53

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

geolocation/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,12 @@ Request location permissions. Will throw if system location services are disabl
171171

172172
#### PositionOptions
173173

174-
| Prop | Type | Description | Default | Since |
175-
| ------------------------ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
176-
| **`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 |
177-
| **`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 |
178-
| **`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 |
174+
| Prop | Type | Description | Default | Since |
175+
| --------------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
176+
| **`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 |
177+
| **`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 |
178+
| **`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 |
179+
| **`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. This parameter is only available for Android. It has no effect on iOS or Web platforms. | <code>5000</code> | 6.1.0 |
179180

180181

181182
#### ClearWatchOptions

geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/Geolocation.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ public void sendLocation(boolean enableHighAccuracy, final LocationResultCallbac
6868
}
6969

7070
@SuppressWarnings("MissingPermission")
71-
public void requestLocationUpdates(boolean enableHighAccuracy, int timeout, final LocationResultCallback resultCallback) {
71+
public void requestLocationUpdates(
72+
boolean enableHighAccuracy,
73+
int timeout,
74+
int minUpdateInterval,
75+
final LocationResultCallback resultCallback
76+
) {
7277
int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
7378
if (resultCode == ConnectionResult.SUCCESS) {
7479
clearLocationUpdates();
@@ -87,7 +92,7 @@ public void requestLocationUpdates(boolean enableHighAccuracy, int timeout, fina
8792

8893
LocationRequest locationRequest = new LocationRequest.Builder(10000)
8994
.setMaxUpdateDelayMillis(timeout)
90-
.setMinUpdateIntervalMillis(5000)
95+
.setMinUpdateIntervalMillis(minUpdateInterval)
9196
.setPriority(priority)
9297
.build();
9398

geolocation/android/src/main/java/com/capacitorjs/plugins/geolocation/GeolocationPlugin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ public void error(String message) {
172172
@SuppressWarnings("MissingPermission")
173173
private void startWatch(final PluginCall call) {
174174
int timeout = call.getInt("timeout", 10000);
175+
int minUpdateInterval = call.getInt("minimumUpdateInterval", 5000);
175176

176177
implementation.requestLocationUpdates(
177178
isHighAccuracy(call),
178179
timeout,
180+
minUpdateInterval,
179181
new LocationResultCallback() {
180182
@Override
181183
public void success(Location location) {

geolocation/src/definitions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,19 @@ export interface PositionOptions {
180180
* @since 1.0.0
181181
*/
182182
maximumAge?: number;
183+
184+
/**
185+
* The minumum update interval for location updates.
186+
*
187+
* If location updates are available faster than this interval then an update
188+
* will only occur if the minimum update interval has expired since the last location update.
189+
*
190+
* This parameter is only available for Android. It has no effect on iOS or Web platforms.
191+
*
192+
* @default 5000
193+
* @since 6.1.0
194+
*/
195+
minimumUpdateInterval?: number;
183196
}
184197

185198
export type WatchPositionCallback = (

geolocation/src/web.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class GeolocationWeb extends WebPlugin implements GeolocationPlugin {
4444
enableHighAccuracy: false,
4545
timeout: 10000,
4646
maximumAge: 0,
47+
minimumUpdateInterval: 5000,
4748
...options,
4849
},
4950
);

0 commit comments

Comments
 (0)