Skip to content

Commit

Permalink
work in Headless JS (#254)
Browse files Browse the repository at this point in the history
Co-authored-by: lavrik acer <valery.lavrik@gmail.com>
  • Loading branch information
valery-lavrik and lavrik acer committed Jul 21, 2023
1 parent 3a8c1b7 commit a2df70e
Showing 1 changed file with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,37 @@ public void getCurrentLocationData(ReadableMap options, Callback success, Callba
Activity currentActivity = mReactContext.getCurrentActivity();

if (currentActivity == null) {
error.invoke(PositionError.buildError(PositionError.ACTIVITY_NULL, "mReactContext.getCurrentActivity() returned null but should be non-null in getCurrentLocationData"));
return;
// error.invoke(PositionError.buildError(PositionError.ACTIVITY_NULL, "mReactContext.getCurrentActivity() returned null but should be non-null in getCurrentLocationData"));



mSingleLocationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
if (locationResult == null) {
error.invoke(PositionError.buildError(PositionError.POSITION_UNAVAILABLE, "No location provided (FusedLocationProvider/lastLocation)."));
return;
}

AndroidLocationManager.LocationOptions locationOptions = AndroidLocationManager.LocationOptions.fromReactMap(options);
Location location = locationResult.getLastLocation();
success.invoke(locationToMap(location));

mFusedLocationClient.removeLocationUpdates(mSingleLocationCallback);
mSingleLocationCallback = null;
}

@Override
public void onLocationAvailability(LocationAvailability locationAvailability) {
if (!locationAvailability.isLocationAvailable()) {
error.invoke(PositionError.buildError(PositionError.POSITION_UNAVAILABLE, "Location not available (FusedLocationProvider/lastLocation)."));
}
}
};
checkLocationSettings(options, mSingleLocationCallback);


return;
}

try {
Expand Down

0 comments on commit a2df70e

Please sign in to comment.