The latest update to the Mapbox Directions API brings fast and accurate rerouting.

Naive rerouting approaches often trigger too late or too early. You may have missed an exit and now you’re waiting for a new route or there’s simply a misread on your location and your navigation system proposes a new route for a wrong starting location.

To increase reaction time and confidence for rerouting, we now use bearings in addition to location to determine whether a driver is on their recommended route or not. For example, if we expect a driver to travel at a bearing of 110 degrees, but measure 130 degrees instead, we have a strong indication that the vehicle has departed from the recommended route and we can request a new route.

I’ve been working to derive highly accurate bearings from map data, this work landed in the Open Source Routing Machine (OSRM) 5.5 release and our Directions API now exposes bearings for each turn in an intersection:

   "intersections" : [
         "bearings" : [ 10, 92, 184, 270 ],
         "out" : 2,
         "in" : 3,
         "entry" : [ "true", "true", "true", "false" ],
         "location" : [ 13.39677, 52.54366 ]
      } ]

For more information on intersections, see the documentation.

Computing real-world bearings from map data

Angles between road edges in simplified map data often differ from the real world. To compute real world bearings from map data, we apply different strategies in different scenarios. Here are a couple of examples.


In the example below a simple approach would detect two independent merging roads with steep turn angles when in fact this is a simple continuation of the same highway separating into dual carriage ways:


Here is a similar case where a highway exit is represented as a sharp turn:


These examples are taken from OpenStreetMap and they are mapped correctly. They simply don’t represent real world turn angles accurately. To address these inconsistencies, we identify various scenarios. In the examples, we estimate bearings by skipping over the first few meters of the turn and looking at the angle of the road segment just after.

Turns on curves

Another scenario are curves and we apply a different strategy. Here, the angle following the immediate intersection represents the accurate turn bearing:

Difference between correct and far-away curves

Get started

Check out the new bearings feature on the Mapbox Directions API and bring turn by turn navigation into your app using the Mapbox Navigation SDK or dive into the code on Github.