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

Refactor location snapping #408

Merged
merged 6 commits into from
Jul 24, 2017
Merged

Refactor location snapping #408

merged 6 commits into from
Jul 24, 2017

Conversation

1ec5
Copy link
Contributor

@1ec5 1ec5 commented Jul 21, 2017

This PR moves the user location snapping code from RouteMapViewController in MapboxNavigation to RouteController in CoreNavigation. Conversely, it moves the snapsUserLocationAnnotationToRoute property from RouteController in CoreNavigation to RouteMapViewController in MapboxNavigation, where it’s actually used.

RouteController now has public location and snappedLocation properties, while NavigationViewController has a snapsUserLocationAnnotationToRoute property.

Along the way, the current road name label now respects course snapping, and various NavigationMapViewDelegate methods have proper Objective-C names. (Previously, selector pieces ended in dangling prepositions instead of nouns.)

#402 partly refactors the location snapping code as well. I think this PR should land before that one to keep things simple.

To summarize:

/ref #321
/cc @ericrwolfe @frederoni @bsudekum

@1ec5 1ec5 added bug Something isn’t working op-ex Refactoring, Tech Debt or any other operational excellence work. topic: location labels Jul 21, 2017
@1ec5 1ec5 self-assigned this Jul 21, 2017
@1ec5 1ec5 requested a review from frederoni July 21, 2017 20:28
style.addSource(source)
streetsSources.append(source)
}
guard let snappedLocation = routeController.snappedLocation else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Relying on two location managers, route controller being the main source for driving navigation and MGLMapView asking for shouldUpdateTo based on its own location updates feels like it's set up for a race condition. However, #402 should eventually move the data in the other direction and the way CLLocationManager is shared throughout the OS should prevent that but there's no guarantee that the snapped location won't lag 1 location update behind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, so should this method be passing location into snappedLocation then?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say the other way around, the route controller should drive the map view, but that might be out of scope for this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree. We should have the route controller drive the map view, and #402 will accomplish that pretty cleanly. In the meantime, do you think what’s happening here is any riskier than what’s in master?

Copy link
Contributor

Choose a reason for hiding this comment

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

It should be the same.

@ericrwolfe ericrwolfe added this to the v0.6.0-2 milestone Jul 21, 2017

This is a raw location received from `locationManager`. To obtain an idealized location, use the `snappedLocation` property.
*/
public var location: CLLocation?
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think this should be public? If a developer needs the raw user location, shouldn't they just create their own location manager?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

snappedLocation has to be public so that MapboxNavigation can use it. I figured if we expose snappedLocation, we might as well expose the raw location too. But we could instead expose snappedLocation as location and pretend there isn't a raw location to begin with.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, that makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 29da08e.

1ec5 added 5 commits July 24, 2017 14:26
Broke up navigationMapView(_:shouldUpdateTo:) into UI and non-UI methods, making it easier to move the non-UI method to Core Navigation.

Update the current road name label based on the snapped location, not the raw location.
Also added RouteController.location for convenience.
@1ec5 1ec5 force-pushed the 1ec5-location-snapping-refactor branch from 9eba4ef to 3f9c942 Compare July 24, 2017 21:37
Hide the raw location from the public. Keep labeling the current road based on the raw location after the user goes off-course or passes the destination.
@1ec5
Copy link
Contributor Author

1ec5 commented Jul 24, 2017

29da08e causes the current road name to continue to be labeled even if the user diverges from the route.

Copy link
Contributor

@bsudekum bsudekum left a comment

Choose a reason for hiding this comment

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

Looks great

@1ec5 1ec5 merged commit ff6f9e5 into master Jul 24, 2017
@1ec5 1ec5 deleted the 1ec5-location-snapping-refactor branch July 24, 2017 21:52
@1ec5 1ec5 mentioned this pull request Aug 24, 2017
12 tasks
@1ec5 1ec5 added the backwards incompatible changes that break backwards compatibility of public API label Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backwards incompatible changes that break backwards compatibility of public API bug Something isn’t working op-ex Refactoring, Tech Debt or any other operational excellence work. topic: location
Projects
None yet
4 participants