mapbox / mapbox/mapbox-navigation-ios
Avoid inconsistencies when a route doubles back on itself
@frederoni is already working on this.
Since Sep 21, 2018.
- Dominant language
- Swift
- Stars
- 918
- Forks
- 326
- Avg merge
- 1h 16m
- Merged PRs (30d)
- 3
Description
When a route doubles back on itself and the user visits the same coordinate a second time, the SDK gets confused, momentarily thinking the user is visiting that coordinate for the first time. There are several ways to reproduce this issue, for example:
* A [Michigan left](https://en.wikipedia.org/wiki/Michigan_left), [superstreet](https://en.wikipedia.org/wiki/Superstreet), or other intersection with turn restrictions requires the user to re-approach a given intersection in order to make a left turn.
* A custom route, such as one that solves the [route inspection problem](https://en.wikipedia.org/wiki/Route_inspection_problem), reaches a four-way intersection from two different approaches and leaves on two different outlets. mapbox/navigation-ios-examples#28 demonstrates such a route.
* A loop ramp in a cloverleaf interchange happens to end directly over or under the spot where it begins.
* A route traverses [the upper deck of a double-decker bridge](https://www.openstreetmap.org/way/159588797#map=17/39.09025/-84.52264), then [the lower deck](https://www.openstreetmap.org/way/159588794).
* A route traverses a [spiral bridge](https://en.wikipedia.org/wiki/Spiral_bridge), such as in a parking garage.
Symptoms of this issue are:

* The maneuver arrow along the route line points in the wrong direction.
* During route simulation, the camera and puck jump or turn in the wrong direction.
* Prior to #1710, the puck would also jump even when not simulating the route.
The problem is that we’re passing a coordinate into `Polyline.trimmed(from:distance:)`, which assumes the coordinate can only appear once in the polyline:
https://github.com/mapbox/mapbox-navigation-ios/blob/f7ba632b731e7d8f8ccbad77df3ea07510bab395/MapboxNavigation/NavigationMapView.swift#L592-L593 https://github.com/mapbox/mapbox-navigation-ios/blob/f7ba632b731e7d8f8ccbad77df3ea07510bab395/MapboxCoreNavigation/SimulatedLocationManager.swift#L157
The most robust fix is to rely on indices into the coordinate array rather than the coordinates themselves. This approach will likely be necessary as part of the navigation-native refactoring. But that could make it much more difficult to memoize the remaining portion of the route, as in #1728.
An alternative approach, which accommodates #1728, is to form polylines from the two nearest steps’ `coordinates` properties rather than `Route.coordinates`. In the event that there are more than two maneuvers in close proximity, we’ll have to expand outward from those two steps. It’ll look pretty similar to `RouteLegProgress.nearbyCoordinates`, but that computed property is too aggressive because it unconditionally adds both the previous and next steps’ coordinates to the result.
/cc @mapbox/navigation-ios @d-prukop
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.