Skip to content

Commit

Permalink
fix(adnroid): fix unnecessary maxage checks (#215)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalchudziak authored Nov 14, 2022
1 parent dbfc03b commit 741a353
Showing 1 changed file with 4 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 741a353

Please sign in to comment.