From 3a4431dfe9d05d7b3d542ddb01934cb4637cbc58 Mon Sep 17 00:00:00 2001 From: Lucas Baumgarten Date: Wed, 10 Jul 2024 16:56:46 -0300 Subject: [PATCH] fix: when using playServices provider the getCurrentPosition error callback is never called (#302) --- .../geolocation/PlayServicesLocationManager.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java b/android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java index 77f6f32..5393fda 100644 --- a/android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java +++ b/android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java @@ -52,7 +52,7 @@ public void getCurrentLocationData(ReadableMap options, Callback success, Callba if (currentActivity == null) { mSingleLocationCallback = createSingleLocationCallback(success, error); - checkLocationSettings(options, mSingleLocationCallback); + checkLocationSettings(options, mSingleLocationCallback, error); return; } @@ -63,7 +63,7 @@ public void getCurrentLocationData(ReadableMap options, Callback success, Callba success.invoke(locationToMap(location)); } else { mSingleLocationCallback = createSingleLocationCallback(success, error); - checkLocationSettings(options, mSingleLocationCallback); + checkLocationSettings(options, mSingleLocationCallback, error); } }); } catch (SecurityException e) { @@ -93,7 +93,7 @@ public void onLocationAvailability(LocationAvailability locationAvailability) { } }; - checkLocationSettings(options, mLocationCallback); + checkLocationSettings(options, mLocationCallback, null); } @Override @@ -104,7 +104,7 @@ public void stopObserving() { mFusedLocationClient.removeLocationUpdates(mLocationCallback); } - private void checkLocationSettings(ReadableMap options, LocationCallback locationCallback) { + private void checkLocationSettings(ReadableMap options, LocationCallback locationCallback, Callback error) { LocationOptions locationOptions = LocationOptions.fromReactMap(options); LocationRequest locationRequest = LocationRequest.create(); locationRequest.setInterval(locationOptions.interval); @@ -129,6 +129,13 @@ private void checkLocationSettings(ReadableMap options, LocationCallback locatio requestLocationUpdates(locationRequest, locationCallback); return; } + + if (error != null) { + error.invoke( + PositionError.buildError(PositionError.POSITION_UNAVAILABLE, "Location not available (FusedLocationProvider/settings).") + ); + return; + } emitError(PositionError.POSITION_UNAVAILABLE, "Location not available (FusedLocationProvider/settings)."); }); }