Skip to content

Commit

Permalink
fix: when using playServices provider the getCurrentPosition error ca…
Browse files Browse the repository at this point in the history
…llback is never called (#302)
  • Loading branch information
ekbaumgarten authored Jul 10, 2024
1 parent 0214d5b commit 3a4431d
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Expand Down Expand Up @@ -93,7 +93,7 @@ public void onLocationAvailability(LocationAvailability locationAvailability) {
}
};

checkLocationSettings(options, mLocationCallback);
checkLocationSettings(options, mLocationCallback, null);
}

@Override
Expand All @@ -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);
Expand All @@ -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).");
});
}
Expand Down

0 comments on commit 3a4431d

Please sign in to comment.