Skip to content

Commit

Permalink
feat(geolocation): add minimumUpdateInterval parameter for `startWa…
Browse files Browse the repository at this point in the history
…tch` (#2272)
  • Loading branch information
alexgerardojacinto authored Dec 6, 2024
1 parent 53acfab commit c6ddc53
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
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. This parameter is only available for Android. It has no effect on iOS or Web platforms. | <code>5000</code> | 6.1.0 |


#### ClearWatchOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();

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
13 changes: 13 additions & 0 deletions geolocation/src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
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

0 comments on commit c6ddc53

Please sign in to comment.