Skip to content

feat: Map Matching and custom routes - #27

Merged
mfazekas merged 3 commits into
mainfrom
feat/map-matching
Oct 29, 2026
Merged

mfazekas merged 3 commits into
mainfrom
feat/map-matching

Conversation

@mfazekas

@mfazekas mfazekas commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Lets apps guide along a route they define, such as a tour, a delivery run or a fleet route, instead of one Directions picks. This is item R3 in the API gap report and the most-requested feature in the unofficial packages (homee #24 and #48, pawan-pk #20 and #29, uju777 #32). It also covers the part of R4 that matters here: turning rerouting off.

Navigation.requestMatchedRoutes({
  coordinates: Position[];          // 2 to 100, validated in JS
  profile?: 'driving-traffic' | 'driving' | 'walking' | 'cycling';
  waypointIndices?: number[];       // defaults to [0, last]
  radiuses?: number[];              // one per coordinate, 0 to 50 m
  language?: string;
  units?: 'metric' | 'imperial';
}): Promise<RouteResponse>;         // same Route host objects; alternatives is always []

Navigation.setRerouteEnabled(enabled: boolean): void;

The returned Route works unchanged with previewRoute, startActiveGuidance and <NavigationView route>. The C++ bindings get a requestMatchedRoutes platform call next to requestRoutes, and the two share one response resolver.

Platform notes:

  1. iOS uses routingProvider().calculateRoutes(options: NavigationMatchOptions). waypointIndices maps to Waypoint.separatesLegs, and radiuses maps to coordinateAccuracy.
  2. Android uses MapboxNavigation.requestMapMatching, which the SDK marks @ExperimentalPreviewMapboxNavigationAPI; the TypeDoc says so. It asks for banner and voice instructions, roundabout exits and annotations to roughly match iOS.
  3. A trace that only matches as several disconnected pieces rejects with code: 'no_single_match' on both platforms. On iOS the SDK silently drops the extra pieces, so we detect a split when the main route ends before the last matched tracepoint.
  4. Neither SDK reroutes a matched route: guidance reports off-route and waits for the user to return. setRerouteEnabled is for Directions routes. Android applies it at once, also mid-guidance. iOS reads it only when the navigation session is created (the first route request or guidance start); a later change has no effect and logs a warning. The TypeDoc and README say this.

Decisions applied: keep rejecting split matches with no_single_match; keep setRerouteEnabled as is with the iOS timing documented, and no configure() API.

Verified on the iOS simulator (iPhone 17) and the Android emulator, both platforms for each step, in the example's "Matched route" screen plus a local harness (not committed) for the live, gap and reroute cases:

  1. Match: 3005 m in 2 legs along the Embarcadero and Jefferson Street.
  2. Simulate: arrival at waypoint 1 (Pier 29), then the final destination.
  3. Live guidance on the matched route with a mock-location drive that leaves the Embarcadero for Broadway and comes back (simctl location start, adb emu geo fix): offRoute turns true, no route change, then false, and progress resumes.
  4. Normal route, live, same drive: with setRerouteEnabled(false) set before the first request, no reroute on either platform. On Android, turning it off mid-guidance also stops reroutes. A control run with rerouting on rerouted at once. On iOS a later call logs the warning.
  5. A trace of two clusters (San Francisco and Oakland) rejects with no_single_match. A trace with an unmatchable jump rejects with route_request_failed. Neither crashes.

Changes since the prototype: iOS now detects split matches (the prototype resolved with only the first piece). The setRerouteEnabled docs were clarified. The example now stops at Pier 29 instead of Pier 39: Android's simulated guidance misses an intermediate waypoint at the Pier 39 junction and stalls off route. A requestRoutes route with a via point there does the same, and live guidance through it works, so it's an SDK replay issue, not a Map Matching one.

Limitations:

  • On iOS, switching from live to simulated guidance in one session can report off-route for a while at the start of the simulation. This is in the existing session code and also happens without matching.
  • The iOS no_single_match check relies on the SDK keeping all tracepoints in NavigationRoutes.waypoints.

Out of scope: a directionsBaseUrl setting (the iOS endpoint override is @_spi(MapboxInternal)), and raw Directions JSON → Route (Android 3.33 keeps NavigationRoute.create internal).

Possible follow-ups: waypoint names, timestamps and tidy, all supported by both SDKs; datasetProfileIdentifier matching the request profile on iOS for walking and cycling (requestRoutes has the same gap).

@mfazekas mfazekas changed the title feat: Map Matching and custom routes (prototype) feat: Map Matching and custom routes Oct 28, 2026
@mfazekas
mfazekas marked this pull request as ready for review October 28, 2026 12:52
Follow an app-supplied path: Map Matching through NavigationMatchOptions on
iOS and requestMapMatching on Android, returning the same Route host objects
as requestRoutes. setRerouteEnabled turns rerouting of Directions routes off.
…ed timing

The iOS SDK drops the further pieces of a split match instead of returning them as alternatives, so detect the split from the main route ending before the last tracepoint.
Android's simulated guidance misses an intermediate waypoint at the Pier 39 junction, also on a requestRoutes route, so the example stops where simulation works on both platforms.
@mfazekas
mfazekas merged commit f3511fa into main Oct 29, 2026
6 checks passed
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.

1 participant