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

Location Services: don't reset desiredAccuracy on every update/error #23209

Closed
wants to merge 1 commit into from
Closed

Location Services: don't reset desiredAccuracy on every update/error #23209

wants to merge 1 commit into from

Conversation

omnikron
Copy link
Contributor

@omnikron omnikron commented Jan 29, 2019

See #7680.

On iOS the RCTLocationObserver delegate is overriding desiredAccuracy every time CLLocationManager calls didUpdateLocations or didFailWithError. desiredAccuracy is reset to
RCT_DEFAULT_LOCATION_ACCURACY (100 meters) This effectively makes it impossible for a react-native app to use any location accuracy other than the default.

This commit simply removes the code which resets the desired accuracy, as there seems to be no rationale for doing so. The reset code was added as part of a large general
change
so the original intention is unclear from the history. If somebody can explain it to me, I'm happy to rework this PR accordingly.

Changelog:

[iOS] [Fixed] - Location Services accuracy constantly reset to default of 100 meters.

Test Plan:

We've been using this in production at FATMAP for nearly a year in a fork of React Native. It works. I'm unclear on how to actually test this in code, so would appreciate any tips.

See #7680.

On iOS the RCTLocationObserver delegate is overriding the intended
`desiredAccuracy` every time CLLocationManager calls
`didUpdateLocations` or `didFailWitError`.  `desiredAccuracy` is set to
`RCT_DEFAULT_LOCATION_ACCURACY` (100 meters) This effectively makes it
impossible for a react-native app to use any location accuracy other
than the default.

This commit simply removes the code which resets the desired accuracy,
as there seems to be no rationale for doing so. The reset code was added
as part of [a large general
change](705a8e0)
so the original intention is unclear from the history.
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 29, 2019
@omnikron omnikron changed the title Don't reset desiredAccuracy on every update/error Location Services: don't reset desiredAccuracy on every update/error Jan 29, 2019
@omnikron
Copy link
Contributor Author

Well, this is an unlikely coincidence – since I started working on this PR a few hours ago a very similar one has been opened (#23207). Happy to unify if it makes sense to do so, although I'm not sure if there is 100% overlap.

@hramos
Copy link
Contributor

hramos commented Jan 29, 2019

That one is not yet merged, so I think it's fine to continue working on this one for the time being.

@hramos
Copy link
Contributor

hramos commented Jan 29, 2019

Did you observe the issue mentioned in the comment, "otherwise update accuracy will force triggering didUpdateLocations, watchPosition would keeping receiving location updates, even there's no location changes." in your fork?

@omnikron
Copy link
Contributor Author

omnikron commented Jan 30, 2019

@hramos there's quite a lot to unpick here, so bear with me! This issue is absolutely critical for us (our users are often in mountainous back country, so precise GPS user location is critical for safety as well as usability) which is why we've been maintaining our fork for 11 months.

Did you observe the issue mentioned in the comment, "otherwise update accuracy will force triggering didUpdateLocations, watchPosition would keeping receiving location updates, even there's no location changes."

I dispute that this is a bug that needed fixing here, so much as an application issue. When setting enableHighAccuracy and starting watchPosition the device will indeed send location updates even if you don't move. This is because the GPS signal will vary/reflect and send minute changes to very high (centimeter) accuracy, even when the device is not moving. However, my take is that this should be handled in application code, not in location services themselves. If you don't need this kind of very high accuracy, then you should simply disable enableHighAccuracy and go back to the default of 100m accuracy, which is probably fine for most 'what's near here' services.

It gets more complicated however, as the comment you mentioned was added in this commit which just adds this check:

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

to me this check alone makes absolutely zero sense. "If desiredAccuracy is not default accuracy then set desiredAccuracy to default accuracy" – what? I feel like I must be missing something, but I can't figure it out.

However, the actual code that I dispute –

_locationManager.desiredAccuracy = RCT_DEFAULT_LOCATION_ACCURACY;

– is added previously in this commit where the comment is simply 'Reset location accuracy'. I don't understand this either – when requesting a high accuracy position from the device, the device sends the first position with high accuracy (which will often be cached from earlier), and then this code resets the accuracy to 100m again, so all future positional updates will be wildly inaccurate!

My interpretation of this is that it has been added in error. If I am missing something then I'd love to know what it is, because as it stands enableHighAccuracy simply doesn't work for iOS devices in React Native.

@hramos
Copy link
Contributor

hramos commented Jan 30, 2019

Thanks for the explanation! I agree this should be handled in product code.

@facebook-github-bot facebook-github-bot added the Import Started This pull request has been imported. This does not imply the PR has been approved. label Jan 30, 2019
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hramos is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cpojer is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@cpojer
Copy link
Contributor

cpojer commented Jan 30, 2019

Retrying because we had an import tooling issue.

@react-native-bot
Copy link
Collaborator

@omnikron merged commit bbcb97a into facebook:master.

@facebook facebook locked as resolved and limited conversation to collaborators Jan 30, 2019
@react-native-bot react-native-bot added the Merged This PR has been merged. label Jan 30, 2019
omnikron referenced this pull request Jan 31, 2019
Reviewed By: @nicklockwood

Differential Revision: D2519624

fb-gh-sync-id: 7366c5ac9e06082448b9fbba3c616aaf8e4183f9
@hramos hramos removed Import Started This pull request has been imported. This does not imply the PR has been approved. labels Feb 6, 2019
matt-oakes pushed a commit to matt-oakes/react-native that referenced this pull request Feb 7, 2019
…acebook#23209)

Summary:
See facebook#7680.

On iOS the RCTLocationObserver delegate is overriding `desiredAccuracy` every time CLLocationManager calls `didUpdateLocations` or `didFailWithError`.  `desiredAccuracy` is reset to
`RCT_DEFAULT_LOCATION_ACCURACY` (100 meters) This effectively makes it impossible for a react-native app to use any location accuracy other than the default.

This commit simply removes the code which resets the desired accuracy, as there seems to be no rationale for doing so. The reset code was added as part of [a large general
change](facebook@705a8e0) so the original intention is unclear from the history. If somebody can explain it to me, I'm happy to rework this PR accordingly.

Changelog:
----------
[iOS] [Fixed] - Location Services accuracy constantly reset to default of 100 meters.
Pull Request resolved: facebook#23209

Differential Revision: D13879497

Pulled By: cpojer

fbshipit-source-id: f3c6c9c5ef698b23b99c407fd764ac990d69bf8c
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged This PR has been merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants