From 70201d61c6864a0e5d6b37766e8f78754211678a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Chudziak?= Date: Mon, 7 Nov 2022 19:22:50 +0100 Subject: [PATCH] fix(adnroid): fix unnecessary maxage checks --- .../PlayServicesLocationManager.java | 24 ++++--------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java b/android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java index fdf836d..c871f30 100644 --- a/android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java +++ b/android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java @@ -48,14 +48,8 @@ public void getCurrentLocationData(ReadableMap options, Callback success, Callba try { mFusedLocationClient.getLastLocation() .addOnSuccessListener(mReactContext.getCurrentActivity(), location -> { - if (location != null) { - if ((SystemClock.currentTimeMillis() - location.getTime()) < locationOptions.maximumAge) { - success.invoke(locationToMap(location)); - } else { - error.invoke(PositionError.buildError( - PositionError.POSITION_UNAVAILABLE, "Last found location is older than maximumAge (FusedLocationProvider/lastLocation).") - ); - } + if (location != null && (SystemClock.currentTimeMillis() - location.getTime()) < locationOptions.maximumAge) { + success.invoke(locationToMap(location)); } else { mSingleLocationCallback = new LocationCallback() { @Override @@ -67,11 +61,7 @@ public void onLocationResult(LocationResult locationResult) { AndroidLocationManager.LocationOptions locationOptions = AndroidLocationManager.LocationOptions.fromReactMap(options); Location location = locationResult.getLastLocation(); - if ((SystemClock.currentTimeMillis() - location.getTime()) < locationOptions.maximumAge) { - success.invoke(locationToMap(location)); - } else { - emitError(PositionError.POSITION_UNAVAILABLE, "Last found location is older than maximumAge (FusedLocationProvider/lastLocation)."); - } + success.invoke(locationToMap(location)); mFusedLocationClient.removeLocationUpdates(mSingleLocationCallback); mSingleLocationCallback = null; @@ -102,14 +92,8 @@ public void onLocationResult(LocationResult locationResult) { return; } - AndroidLocationManager.LocationOptions locationOptions = AndroidLocationManager.LocationOptions.fromReactMap(options); - Location location = locationResult.getLastLocation(); - if ((SystemClock.currentTimeMillis() - location.getTime()) < locationOptions.maximumAge) { - mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) + mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit("geolocationDidChange", locationToMap(locationResult.getLastLocation())); - } else { - emitError(PositionError.POSITION_UNAVAILABLE, "Last found location is older than maximumAge (FusedLocationProvider/observer)."); - } } @Override