Skip to content

Commit

Permalink
feat(geolocation): add interval and minInterval options in watch posi…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Toilal committed Jun 12, 2024
1 parent 39fb409 commit d9bb366
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
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, long timeout, long interval, long minInterval, final LocationResultCallback resultCallback) {
int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
if (resultCode == ConnectionResult.SUCCESS) {
clearLocationUpdates();
Expand All @@ -85,9 +85,9 @@ public void requestLocationUpdates(boolean enableHighAccuracy, int timeout, fina
int lowPriority = networkEnabled ? Priority.PRIORITY_BALANCED_POWER_ACCURACY : Priority.PRIORITY_LOW_POWER;
int priority = enableHighAccuracy ? Priority.PRIORITY_HIGH_ACCURACY : lowPriority;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.util.HashMap;
import java.util.Map;

import static com.google.android.gms.location.LocationRequest.Builder.IMPLICIT_MIN_UPDATE_INTERVAL;

@CapacitorPlugin(
name = "Geolocation",
permissions = {
Expand Down Expand Up @@ -171,11 +173,15 @@ public void error(String message) {

@SuppressWarnings("MissingPermission")
private void startWatch(final PluginCall call) {
int timeout = call.getInt("timeout", 10000);
long timeout = call.getLong("timeout", 10000L);
long interval = call.getLong("interval", 10000L);
long minInterval = call.getLong("minInterval", IMPLICIT_MIN_UPDATE_INTERVAL);

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

/**
* The desired interval in milliseconds between each location updates (Android only).
*
* @default 10000
*/
interval?: number;

/**
* Sets the fastest allowed interval in milliseconds between each location updates. (Android only)
*
* Location updates may arrive faster than the desired interval, but will never arrive faster than specified here.
*
* Default value is a special value that match desired interval value.
*
* @default -1
*/
minInterval?: number;
}

export type WatchPositionCallback = (
Expand Down

0 comments on commit d9bb366

Please sign in to comment.