Skip to content

Commit aacd2d9

Browse files
zjj010104facebook-github-bot-7
authored and
facebook-github-bot-7
committed
fix watchPosition keep updating location
Reviewed By: @nicklockwood Differential Revision: D2519624 fb-gh-sync-id: 7366c5ac9e06082448b9fbba3c616aaf8e4183f9
1 parent da359c3 commit aacd2d9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Libraries/Geolocation/RCTLocationObserver.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,11 @@ - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray
284284
[_locationManager stopUpdatingLocation];
285285
}
286286

287-
// Reset location accuracy
288-
_locationManager.desiredAccuracy = RCT_DEFAULT_LOCATION_ACCURACY;
287+
// Reset location accuracy if desiredAccuracy is changed.
288+
// Otherwise update accuracy will force triggering didUpdateLocations, watchPosition would keeping receiving location updates, even there's no location changes.
289+
if (ABS(_locationManager.desiredAccuracy - RCT_DEFAULT_LOCATION_ACCURACY) > 0.000001) {
290+
_locationManager.desiredAccuracy = RCT_DEFAULT_LOCATION_ACCURACY;
291+
}
289292
}
290293

291294
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
@@ -318,8 +321,11 @@ - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *
318321
}
319322
[_pendingRequests removeAllObjects];
320323

321-
// Reset location accuracy
322-
_locationManager.desiredAccuracy = RCT_DEFAULT_LOCATION_ACCURACY;
324+
// Reset location accuracy if desiredAccuracy is changed.
325+
// Otherwise update accuracy will force triggering didUpdateLocations, watchPosition would keeping receiving location updates, even there's no location changes.
326+
if (ABS(_locationManager.desiredAccuracy - RCT_DEFAULT_LOCATION_ACCURACY) > 0.000001) {
327+
_locationManager.desiredAccuracy = RCT_DEFAULT_LOCATION_ACCURACY;
328+
}
323329
}
324330

325331
- (void)checkLocationConfig

0 commit comments

Comments
 (0)