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] Expose option for distance filtering on location updates. #5563

Closed
wants to merge 1 commit into from

Conversation

christopherdro
Copy link
Contributor

@christopherdro christopherdro commented Jan 26, 2016

My original implementation involved creating a RCT_ENUM_CONVERTER with CLLocationAccuracy on iOS and a Hashmap on Android that would convert string values to doubles for distance filtering.

I got this to work just fine but realized that I made things more complicated than they needed to be and simplified everything by just having the option be a decimal value (in meters) that works both for iOS and Android.

The only thing i'm not sure about is if we can set arbitrary values for CLLocationManager's distance filter.
@nicklockwood Any idea?

@facebook-github-bot
Copy link
Contributor

By analyzing the blame information on this pull request, we identified @mkonicek, @nicklockwood and @sahrens to be potential reviewers.

@facebook-github-bot facebook-github-bot added GH Review: review-needed CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. labels Jan 26, 2016
@lelandrichardson
Copy link
Contributor

@christopherdro my understanding is that the distance filter is separate from the idea of "accuracy", but is instead related to minimum distance for a "change" in location to have occurred. It seems that in this case, using an arbitrary double value should be just fine.

@christopherdro
Copy link
Contributor Author

@lelandrichardson That's correct the idea of accuracy and distance are different.

Here is what docs say about distance filter.

The minimum distance (measured in meters) a device must move horizontally before an update event is generated.

I figured it would be just fine but with iOS you just never know.

@lelandrichardson
Copy link
Contributor

It seems to me like using a double should work fine 👍

@rt2zz
Copy link
Contributor

rt2zz commented Jan 29, 2016

+1 confirmed working

@rt2zz
Copy link
Contributor

rt2zz commented Jan 29, 2016

Upon further testing, I believe there is an edge case where on Android 0 is treated as no distance filter but on iOS actually does filter results (perhaps 0 -> infinity)

To make this more intuitive we could set 0 to kCLDistanceFilterNone

@nicklockwood
Copy link
Contributor

@rt2xx that makes sense to me.

@facebook-github-bot
Copy link
Contributor

@christopherdro updated the pull request.

@christopherdro
Copy link
Contributor Author

@rt2zz Nice catch!

Entering 0 as an option would still default RCT_DEFAULT_LOCATION_ACCURACY since the conditional would still evaluate it as false.

This should now be working properly with the updated nested ternary operator.

@facebook-github-bot
Copy link
Contributor

@christopherdro updated the pull request.

@christopherdro
Copy link
Contributor Author

Possible solution for #1240

@nicklockwood
Copy link
Contributor

@facebook-github-bot shipit

@facebook-github-bot
Copy link
Contributor

Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1701598750054106/int_phab to review.

@ghost ghost closed this in 109036b Feb 6, 2016
pglotov pushed a commit to pglotov/react-native that referenced this pull request Mar 15, 2016
Summary:
My original implementation involved creating a `RCT_ENUM_CONVERTER` with `CLLocationAccuracy` on iOS and a Hashmap on Android that would convert `string` values to `doubles` for distance filtering.

I got this to work just fine but realized that I made things more complicated than they needed to be and simplified everything by just have the option be a decimal value (in meters) that works both for iOS and Android.

The only thing i'm not sure about is if we can set arbitrary values for CLLocationManager's distance filter.
nicklockwood  Any idea?
Closes facebook#5563

Reviewed By: svcscm

Differential Revision: D2908250

Pulled By: nicklockwood

fb-gh-sync-id: d83c12b3ce7c343f413749a2cd614b3bf04d6750
@@ -128,7 +134,7 @@ - (void)beginLocationUpdates
{
if (!_locationManager) {
_locationManager = [CLLocationManager new];
_locationManager.distanceFilter = RCT_DEFAULT_LOCATION_ACCURACY;
_locationManager.distanceFilter = _observerOptions.distanceFilter;
Copy link
Contributor

Choose a reason for hiding this comment

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

@christopherdro should we move _locationManager.distanceFilter = _observerOptions.distanceFilter outside of the if (!_locationManager) so this could be changed when stoping and watching the location again? Also it seems that beginLocationUpdatesWithDesiredAccuracy is called from getCurrentPosition and it is not initialized from beginLocationUpdatesWithDesiredAccuracy would this be an issue if the value is nil or just be a noop?

Copy link
Contributor Author

@christopherdro christopherdro Apr 15, 2016

Choose a reason for hiding this comment

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

I think this change was made by @nicklockwood after he accepted my PR.

I'm not quite sure I understand the issue with beginLocationUpdatesWIthDesiredAccuracy. Could you possible give an example of what the issue is?

Copy link
Contributor

Choose a reason for hiding this comment

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

I just tested calling getCurrentPosition from the start and it seems that it does not crash because structs have a default value:
screen shot 2016-04-14 at 8 44 09 pm
I think using RCT_DEFAULT_LOCATION_ACCURACY or kCLDistanceFilterNone should be used here.

Copy link
Contributor

@jrichardlai jrichardlai Apr 15, 2016

Choose a reason for hiding this comment

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

Nevermind there is a fix 49b2805
Update: actually this was for desiredAccuracy

@janaka120
Copy link

is distanceFilter working properly now.

@rt2zz
Copy link
Contributor

rt2zz commented Nov 6, 2016

yes

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants