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

Snap to route #57

Merged
merged 9 commits into from
Mar 22, 2017
Merged

Snap to route #57

merged 9 commits into from
Mar 22, 2017

Conversation

frederoni
Copy link
Contributor

WIP
Outlined how snap to route could work.

@1ec5 👀


@interface MGLMapView (MGLNavigationAdditions)

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be exposed in mapbox-gl-native

Copy link
Contributor

Choose a reason for hiding this comment

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

As I mentioned in mapbox/mapbox-gl-native#6867, I think the map SDK should instead expose more specific methods like -didUpdateLocationWithUserTrackingAnimated:.

Copy link
Contributor

Choose a reason for hiding this comment

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

Whichever method we choose to override, I'm okay with doing this logic here for the time being while we experiment.

func navigationMapView(_ mapView: NavigationMapView, shouldUpdateTo location: CLLocation) -> CLLocation?
}

public class NavigationMapView: MGLMapView {
Copy link
Contributor

Choose a reason for hiding this comment

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

This code should go in a separate NavigationMapView.swift file.

@bsudekum
Copy link
Contributor

Should be make snapping an optional param?

@bsudekum bsudekum mentioned this pull request Mar 11, 2017
@bsudekum
Copy link
Contributor

I think we should also look into snapping bearing/heading.

@bsudekum
Copy link
Contributor

@1ec5 this is ready for review again. Made snapping optional with 15da62d

Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

Some opportunities for better naming below.

I agree with #57 (comment) that this implementation is basically a hack (albeit a well-written one!) until we expose a method upstream as part of mapbox/mapbox-gl-native#6867.

@@ -24,6 +24,12 @@ open class RouteController: NSObject {


/*
If true, the user puck is snapped to closest location on the route.
*/
public var snapUserToRoute = false
Copy link
Contributor

Choose a reason for hiding this comment

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

“Snap user to route” sounds like a command, so this sounds like an action method instead of a property that can be set. (In Objective-C, an action method and a property getter call can look identical.) Also, it sounds funny to say that we’re moving the user themselves; we’re actually moving the user location annotation.

Let’s call this property snapsUserLocationAnnotationToRoute. It’s a mouthful, but the developer won’t have to call it often anyways.

/*
Accepted deviation excluding horizontal accuracy before the user is considered to be off route.
*/
public var RouteControllerHorizontalAccuracyAnomaly: CLLocationDistance = 10
Copy link
Contributor

Choose a reason for hiding this comment

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

This global variable doesn’t represent an anomaly; it represents the maximum deviation distance that can be considered an anomaly. How about calling this global RouteControllerUserLocationSnappingDistance, to describe the desired output instead of one specific input (which may not be the only output in the future)?


extension RouteMapViewController: NavigationMapViewDelegate {

func navigationMapView(_ mapView: NavigationMapView, shouldUpdateTo location: CLLocation) -> CLLocation? {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a weird name for a method that returns a CLLocation. The name implies that it returns only a Boolean indicating whether the map view should… update.

Copy link
Contributor

Choose a reason for hiding this comment

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

This will have to do for now, although it’s going to look really weird in Objective-C.

Eventually, as part of mapbox/mapbox-gl-native#6867, we’ll want the MGLMapViewDelegate method upstream to accept an already positioned MGLUserLocation, rather than the raw CLLocationCoordinate2D, so that the heading can also be manipulated.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add @objc(navigationMapView:shouldUpdateToLocation:) to help with Objective-C.

Copy link
Contributor

@1ec5 1ec5 left a comment

Choose a reason for hiding this comment

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

Two minor change requests below in MGLMapView+MGLNavigationAdditions.h.

I’d prefer that we wait until @frederoni or I get a chance to pick up mapbox/mapbox-gl-native#6867, but if we need to land this feature before the next iOS SDK release, then so be it.


extension RouteMapViewController: NavigationMapViewDelegate {

func navigationMapView(_ mapView: NavigationMapView, shouldUpdateTo location: CLLocation) -> CLLocation? {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will have to do for now, although it’s going to look really weird in Objective-C.

Eventually, as part of mapbox/mapbox-gl-native#6867, we’ll want the MGLMapViewDelegate method upstream to accept an already positioned MGLUserLocation, rather than the raw CLLocationCoordinate2D, so that the heading can also be manipulated.

@@ -0,0 +1,7 @@
#import <Mapbox/Mapbox.h>

@interface MGLMapView (MGLNavigationAdditions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than redeclare the method below, let’s have this class extension conform to the CLLocationManagerDelegate protocol.

@@ -0,0 +1,7 @@
#import <Mapbox/Mapbox.h>

@interface MGLMapView (MGLNavigationAdditions)
Copy link
Contributor

Choose a reason for hiding this comment

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

Also add a FIXME: comment noting that this class extension will be reworked following mapbox/mapbox-gl-native#6867.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants