@@ -48,14 +48,8 @@ public void getCurrentLocationData(ReadableMap options, Callback success, Callba
48
48
try {
49
49
mFusedLocationClient .getLastLocation ()
50
50
.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 ));
59
53
} else {
60
54
mSingleLocationCallback = new LocationCallback () {
61
55
@ Override
@@ -67,11 +61,7 @@ public void onLocationResult(LocationResult locationResult) {
67
61
68
62
AndroidLocationManager .LocationOptions locationOptions = AndroidLocationManager .LocationOptions .fromReactMap (options );
69
63
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 ));
75
65
76
66
mFusedLocationClient .removeLocationUpdates (mSingleLocationCallback );
77
67
mSingleLocationCallback = null ;
@@ -102,14 +92,8 @@ public void onLocationResult(LocationResult locationResult) {
102
92
return ;
103
93
}
104
94
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 )
109
96
.emit ("geolocationDidChange" , locationToMap (locationResult .getLastLocation ()));
110
- } else {
111
- emitError (PositionError .POSITION_UNAVAILABLE , "Last found location is older than maximumAge (FusedLocationProvider/observer)." );
112
- }
113
97
}
114
98
115
99
@ Override
0 commit comments