Skip to content

Commit 741a353

Browse files
fix(adnroid): fix unnecessary maxage checks (#215)
1 parent dbfc03b commit 741a353

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

android/src/main/java/com/reactnativecommunity/geolocation/PlayServicesLocationManager.java

+4-20
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,8 @@ public void getCurrentLocationData(ReadableMap options, Callback success, Callba
4848
try {
4949
mFusedLocationClient.getLastLocation()
5050
.addOnSuccessListener(mReactContext.getCurrentActivity(), location -> {
51-
if (location != null) {
52-
if ((SystemClock.currentTimeMillis() - location.getTime()) < locationOptions.maximumAge) {
53-
success.invoke(locationToMap(location));
54-
} else {
55-
error.invoke(PositionError.buildError(
56-
PositionError.POSITION_UNAVAILABLE, "Last found location is older than maximumAge (FusedLocationProvider/lastLocation).")
57-
);
58-
}
51+
if (location != null && (SystemClock.currentTimeMillis() - location.getTime()) < locationOptions.maximumAge) {
52+
success.invoke(locationToMap(location));
5953
} else {
6054
mSingleLocationCallback = new LocationCallback() {
6155
@Override
@@ -67,11 +61,7 @@ public void onLocationResult(LocationResult locationResult) {
6761

6862
AndroidLocationManager.LocationOptions locationOptions = AndroidLocationManager.LocationOptions.fromReactMap(options);
6963
Location location = locationResult.getLastLocation();
70-
if ((SystemClock.currentTimeMillis() - location.getTime()) < locationOptions.maximumAge) {
71-
success.invoke(locationToMap(location));
72-
} else {
73-
emitError(PositionError.POSITION_UNAVAILABLE, "Last found location is older than maximumAge (FusedLocationProvider/lastLocation).");
74-
}
64+
success.invoke(locationToMap(location));
7565

7666
mFusedLocationClient.removeLocationUpdates(mSingleLocationCallback);
7767
mSingleLocationCallback = null;
@@ -102,14 +92,8 @@ public void onLocationResult(LocationResult locationResult) {
10292
return;
10393
}
10494

105-
AndroidLocationManager.LocationOptions locationOptions = AndroidLocationManager.LocationOptions.fromReactMap(options);
106-
Location location = locationResult.getLastLocation();
107-
if ((SystemClock.currentTimeMillis() - location.getTime()) < locationOptions.maximumAge) {
108-
mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
95+
mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
10996
.emit("geolocationDidChange", locationToMap(locationResult.getLastLocation()));
110-
} else {
111-
emitError(PositionError.POSITION_UNAVAILABLE, "Last found location is older than maximumAge (FusedLocationProvider/observer).");
112-
}
11397
}
11498

11599
@Override

0 commit comments

Comments
 (0)