Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Geolocation Accuracy and Cached Location Bug #6198

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions Libraries/Geolocation/RCTLocationObserver.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ - (dispatch_queue_t)methodQueue

#pragma mark - Private API

- (void)beginLocationUpdates
- (void)beginLocationUpdatesInDesiredAccuracy:(CLLocationAccuracy)desiredAccuracy
{
if (!_locationManager) {
_locationManager = [CLLocationManager new];
Expand All @@ -147,6 +147,7 @@ - (void)beginLocationUpdates
[_locationManager requestWhenInUseAuthorization];
}

_locationManager.desiredAccuracy = desiredAccuracy;
// Start observing location
[_locationManager startUpdatingLocation];
}
Expand Down Expand Up @@ -178,8 +179,7 @@ - (void)timeout:(NSTimer *)timer
_observerOptions.accuracy = MIN(_observerOptions.accuracy, request.options.accuracy);
}

_locationManager.desiredAccuracy = _observerOptions.accuracy;
[self beginLocationUpdates];
[self beginLocationUpdatesInDesiredAccuracy:_observerOptions.accuracy];
_observingLocation = YES;
}

Expand Down Expand Up @@ -225,8 +225,8 @@ - (void)timeout:(NSTimer *)timer

// Check if previous recorded location exists and is good enough
if (_lastLocationEvent &&
CFAbsoluteTimeGetCurrent() - [RCTConvert NSTimeInterval:_lastLocationEvent[@"timestamp"]] < options.maximumAge &&
[_lastLocationEvent[@"coords"][@"accuracy"] doubleValue] >= options.accuracy) {
[NSDate date].timeIntervalSince1970 - [RCTConvert NSTimeInterval:_lastLocationEvent[@"timestamp"]] < options.maximumAge &&
[_lastLocationEvent[@"coords"][@"accuracy"] doubleValue] <= options.accuracy) {

// Call success block with most recent known location
successBlock(@[_lastLocationEvent]);
Expand All @@ -249,8 +249,11 @@ - (void)timeout:(NSTimer *)timer
[_pendingRequests addObject:request];

// Configure location manager and begin updating location
_locationManager.desiredAccuracy = MIN(_locationManager.desiredAccuracy, options.accuracy);
[self beginLocationUpdates];
if (_locationManager) {
[self beginLocationUpdatesInDesiredAccuracy:MIN(_locationManager.desiredAccuracy, options.accuracy)];
} else {
[self beginLocationUpdatesInDesiredAccuracy:options.accuracy];
}
}

#pragma mark - CLLocationManagerDelegate
Expand Down