Skip to content

Commit

Permalink
chore: set max update age instead of expiration duration (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalchudziak authored Sep 1, 2024
1 parent 99f5636 commit 40b8028
Showing 1 changed file with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 -> {
Expand Down

0 comments on commit 40b8028

Please sign in to comment.