mapbox / mapbox/mapbox-navigation-ios
Calibrate course based on heading changes
Nobody has claimed this yet.
- Dominant language
- Swift
- Stars
- 918
- Forks
- 326
- Avg merge
- 1h 16m
- Merged PRs (30d)
- 3
Description
We currently use only the course from GPS location updates, ignoring the heading from the magnetometer, because the phone doesn’t necessarily face the same direction that the user is headed. For example, it could be sitting in a cupholder rotated to the side to face the driver, in which case the heading is constantly offset.
Unfortunately, the course is just as noisy as any other component in a GPS location update, typically noisier than headings. The map can end up rotating back and forth even as the user travels in a straight line, potentially wasting energy as the map performs unnecessary symbol placement (see mapbox/mapbox-gl-native#9031).
We should ignore changes in course that aren’t accompanied by changes in heading. The assumption is that any real change in course would require the phone to face a different direction, whether it’s in a car cupholder or in a pedestrian’s hand. (However, #2215 would switch to headings for walking directions, ignoring the course outright.)
RouteController currently passes the course to MBNavigator verbatim and never uses the heading:
https://github.com/mapbox/mapbox-navigation-ios/blob/05c1f9fe54a9a0aa16767537ded952d7c313d0d7/MapboxCoreNavigation/RouteController.swift#L190 https://github.com/mapbox/mapbox-navigation-ios/blob/05c1f9fe54a9a0aa16767537ded952d7c313d0d7/MapboxCoreNavigation/MBNavigator.swift#L10
LegacyRouteController only disqualifies a course if the device doesn’t support course readings at all (such as in an iPhone simulator). It doesn’t even use the heading for the so-called heading-based turn completion heuristic:
https://github.com/mapbox/mapbox-navigation-ios/blob/05c1f9fe54a9a0aa16767537ded952d7c313d0d7/MapboxCoreNavigation/LegacyRouteController.swift#L100-L107 https://github.com/mapbox/mapbox-navigation-ios/blob/05c1f9fe54a9a0aa16767537ded952d7c313d0d7/MapboxCoreNavigation/LegacyRouteController.swift#L457-L460 https://github.com/mapbox/mapbox-navigation-ios/blob/dc9f1e9be68b18ca4f57882c98e0a58e85461507/MapboxCoreNavigation/CLLocationDirection.swift#L16-L18
NavigationMapView uses the course verbatim and doesn’t use the heading for anything, though #2215 would switch to heading for walking directions:
https://github.com/mapbox/mapbox-navigation-ios/blob/05c1f9fe54a9a0aa16767537ded952d7c313d0d7/MapboxNavigation/NavigationMapView.swift#L344
/ref #2046
/cc @mapbox/navigation-ios @avi-c @d-prukop @mapbox/navnative
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.
Research direction
Start by reading the linked sections of RouteController.swift, MBNavigator.swift, LegacyRouteController.swift, CLLocationDirection.swift, and NavigationMapView.swift to trace how course and heading are passed and used. Determine how course changes should be filtered by heading changes, then verify that straight travel no longer produces unnecessary map rotation while genuine direction changes remain responsive.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ios, swift
- Domain
- mobile
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100