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

Geolocation API automatically reverts to 100m accuracy on iOS #7680

Closed
4 tasks done
rburgst opened this issue May 22, 2016 · 5 comments
Closed
4 tasks done

Geolocation API automatically reverts to 100m accuracy on iOS #7680

rburgst opened this issue May 22, 2016 · 5 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@rburgst
Copy link

rburgst commented May 22, 2016

The current implementation of the geolocation API always reverts back to an accuracy of 100m after receiving the first location update.

  • Code snippet

https://facebook.github.io/react-native/docs/geolocation.html

componentDidMount() {
    this.startGpsWatch();
}

startGpsWatch() {
    let geoOptions :GeoOptions = {
        enableHighAccuracy: true,
        distanceFilter: 3,
        timeout: 20000,
        maximumAge: 4000,
        accuracy: 1,
    };
    this.watchID = navigator.geolocation.watchPosition(
        this.onLastPositionReceived.bind(this),
        this.onLastPositionError.bind(this),
        geoOptions
    );

onLastPositionReceived(position) {
    console.info("accuracy", position.accuracy);
}
  • What's the version of React Native you're using?

latest 0.26.1

  • Does this occur on iOS, Android or both?

only on iOS

  • Are you using Mac, Linux or Windows?

Mac

The issue seems to stem from this code

if (ABS(_locationManager.desiredAccuracy - RCT_DEFAULT_LOCATION_ACCURACY) > 0.000001) {

- (void)locationManager:(CLLocationManager *)manager
   didUpdateLocations:(NSArray<CLLocation *> *)locations
{
   ...

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

Where RCT_DEFAULT_LOCATION_ACCURACY is 100m.

The rationale for this code is somewhat unclear to me. The comment does not seem to fit to the implementation.

@lacker
Copy link
Contributor

lacker commented Oct 21, 2016

The code you are linking to is inside didFailWithError so it looks like the accuracy is only resetting on an error. My suspicion is that in your project it is actually erroring a lot for some reason which is causing those resets. I'm going to close this issue since it's been a while but if this theory is incorrect feel free to reopen.

@lacker lacker closed this as completed Oct 21, 2016
@rburgst
Copy link
Author

rburgst commented Oct 24, 2016

In my tests this was happening quite frequently therefore ruining the functionality. IMHO the code should still revert to the previously set desiredAccuary.

@rburgst
Copy link
Author

rburgst commented Oct 24, 2016

In addition the same code can be found in https://github.com/facebook/react-native/blob/master/Libraries/Geolocation/RCTLocationObserver.m#L269

- (void)locationManager:(CLLocationManager *)manager
     didUpdateLocations:(NSArray<CLLocation *> *)locations

@leokaessner
Copy link

@rburgst Did you find a solution? We still struggle with that problem. As the constant is defined as makro, we even can't really subclass or categorize the RCTLocationObserver.

@rburgst
Copy link
Author

rburgst commented Jun 1, 2017 via email

omnikron referenced this issue Feb 22, 2018
Reviewed By: @nicklockwood

Differential Revision: D2519624

fb-gh-sync-id: 7366c5ac9e06082448b9fbba3c616aaf8e4183f9
@facebook facebook locked as resolved and limited conversation to collaborators Jul 19, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests

4 participants