From 40b80286bd5a58c5364f5b40a4b6060d2f717535 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Chudziak?= Date: Sun, 1 Sep 2024 10:18:41 +0200 Subject: [PATCH] chore: set max update age instead of expiration duration (#330) --- .../PlayServicesLocationManager.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java b/android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java index b7b8050..423f7a5 100644 --- a/android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java +++ b/android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java @@ -23,6 +23,7 @@ import com.google.android.gms.location.LocationResult; import com.google.android.gms.location.LocationServices; import com.google.android.gms.location.LocationSettingsRequest; +import com.google.android.gms.location.Priority; import com.google.android.gms.location.SettingsClient; @SuppressLint("MissingPermission") @@ -100,22 +101,22 @@ public void stopObserving() { private void checkLocationSettings(ReadableMap options, LocationCallback locationCallback, Callback error) { LocationOptions locationOptions = LocationOptions.fromReactMap(options); - LocationRequest locationRequest = LocationRequest.create(); - locationRequest.setInterval(locationOptions.interval); + LocationRequest.Builder requestBuilder = new LocationRequest.Builder(locationOptions.interval); + requestBuilder.setPriority(locationOptions.highAccuracy ? Priority.PRIORITY_HIGH_ACCURACY : Priority.PRIORITY_LOW_POWER); + requestBuilder.setMaxUpdateAgeMillis((long) locationOptions.maximumAge); + if (locationOptions.fastestInterval >= 0) { - locationRequest.setFastestInterval(locationOptions.fastestInterval); + requestBuilder.setMinUpdateIntervalMillis(locationOptions.fastestInterval); } - locationRequest.setExpirationDuration((long) locationOptions.maximumAge); + if (locationOptions.distanceFilter >= 0) { - locationRequest.setSmallestDisplacement(locationOptions.distanceFilter); + requestBuilder.setMinUpdateDistanceMeters(locationOptions.distanceFilter); } - locationRequest.setPriority( - locationOptions.highAccuracy ? LocationRequest.PRIORITY_HIGH_ACCURACY : LocationRequest.PRIORITY_LOW_POWER - ); + LocationRequest locationRequest = requestBuilder.build(); - LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder(); - builder.addLocationRequest(locationRequest); - LocationSettingsRequest locationSettingsRequest = builder.build(); + LocationSettingsRequest.Builder settingsBuilder = new LocationSettingsRequest.Builder(); + settingsBuilder.addLocationRequest(locationRequest); + LocationSettingsRequest locationSettingsRequest = settingsBuilder.build(); mLocationServicesSettingsClient.checkLocationSettings(locationSettingsRequest) .addOnSuccessListener(locationSettingsResponse -> requestLocationUpdates(locationRequest, locationCallback)) .addOnFailureListener(err -> {