Skip to main content

Navigation products

Mapbox provides a collection of APIs to add directions-related services to your application. Generate a route with trip durations, estimated distances, and turn-by-turn directions with the Mapbox Directions API, retrieve travel times between many points with the Mapbox Matrix API, compute areas that are reachable within a specified amount of time from a location by the Mapbox Isochrone API, retrieve duration-optimized trips between points with the Mapbox Optimization API, or align existing fuzzy routes to the routeable network with the Mapbox Map Matching API. From routing deliveries efficiently to providing navigation steps for wayfinding, Mapbox provides the tools necessary to integrate directions into your application.

This guide provides an overview of how the routing network is created, how to add directions services to applications across platforms, how to provide feedback, and relevant documentation to help you get started.

Directions demo

In the demo below, you can enter two locations to be the starting and ending points of a Directions API query, then view the response as raw JSON:

The demo uses the Mapbox Directions API through the Mapbox GL Directions plugin with Mapbox GL JS to add driving, cycling, or walking directions to a web application.

The Mapbox Directions API returns a JSON object containing a route with trip durations, estimated distances, and turn-by-turn instructions. When using the Mapbox GL Directions plugin, all this information will be automatically added to the map when a request is complete. By default, the plugin will also display turn-by-turn instructions. This example hides the turn-by-turn instructions and displays the raw JSON response to illustrate what information is included in the directions response object.

How directions work

When you provide two or more points to the Mapbox Directions API, it returns a route as a GeoJSON line that you can add to your map, text for turn-by-turn instructions that you can choose to display in your application, and the distance and estimated travel times for the mode of transportation you selected. There are many other services that extend Mapbox directions that allow you to fix messy GPS traces to the network or optimize trips to multiple stops on a single journey.

The routing network

The Mapbox routing network can create routes and optimized trips, and is used to calculate the most efficient path for a given mode of transportation (driving, cycling, and walking). The routing network includes a robust network of roads and paths (also known as ways) with distinct attributes like speed limits, turn lane restrictions, mode of travel, and accessibility for bikes and pedestrians.

Ways
A way is an OpenStreetMap term used to describe an ordered list of nodes (points) which normally also has at least one tag, or description. For the purposes of the Mapbox Navigation service APIs, ways can be roads, foot paths, or bicycle lanes.

Travel times

The Mapbox Directions API, Matrix API, and Optimization API all provide estimated trip durations. The time it takes to travel from one point to another is determined by many factors, including:

Traffic data

Incorporate real-time and typical traffic data using the mapbox/driving-traffic routing profile into route selection and ETA generation with the Mapbox Directions API, Map Matching API, Matrix API, either into computing areas of reachability with the Mapbox Isochrone API, or add a traffic layer to road geometries on a visual map. Read more about our traffic tileset in Mapbox data.

The mapbox/driving-traffic routing profile is available globally, but the availability of real-time traffic-dependent travel times varies by country. Real-time traffic shows speeds that have been directly observed in the 15 minutes before data generation. Real-time traffic data is useful if there are atypical traffic patterns (for example, during severe weather events or accidents).

If real-time traffic conditions are not available in a specific country, typical traffic conditions will be used instead. Typical traffic is an estimate for traffic speeds at a specific location, at a specific time, based on historical observations. Typical traffic data reflects normal traffic conditions during a typical week.

Real-time and typical traffic

For the following countries, the returned ETA is calculated using both real-time and typical traffic data along the requested route.

  • Andorra
  • Antigua and Barbuda
  • Argentina
  • Armenia
  • Aruba
  • Australia
  • Austria
  • The Bahamas
  • Bahrain
  • Barbados
  • Belarus
  • Belgium
  • Bermuda
  • Brazil
  • British Virgin Islands
  • Brunei Darussalam
  • Bulgaria
  • Cambodia
  • Canada
  • Cayman Islands
  • Chile
  • Colombia
  • Costa Rica
  • Cyprus
  • Czech Republic
  • Denmark
  • Dominican Republic
  • Ecuador
  • El Salvador
  • Estonia
  • Faroe Islands
  • Finland
  • France
  • Germany
  • Gibraltar
  • Grenada
  • Guam
  • Guatemala
  • Hong Kong SAR, China
  • Hungary
  • Indonesia
  • Iran, Islamic Rep.
  • Ireland
  • Isle of Man
  • Israel
  • Italy
  • Japan
  • Jordan
  • Korea, Rep.
  • Kuwait
  • Kyrgyz Republic
  • Latvia
  • Lebanon
  • Liechtenstein
  • Luxembourg
  • Macao SAR, China
  • Malaysia
  • Maldives
  • Malta
  • Mexico
  • Moldova
  • Monaco
  • Montenegro
  • Netherlands
  • New Zealand
  • Northern Mariana Islands
  • Norway
  • Panama
  • Peru
  • Poland
  • Puerto Rico
  • Qatar
  • Romania
  • Russian Federation
  • San Marino
  • Saudi Arabia
  • Serbia
  • Singapore
  • Slovak Republic
  • Slovenia
  • Spain
  • St. Kitts and Nevis
  • St. Lucia
  • St. Vincent and the Grenadines
  • Sweden
  • Switzerland
  • Taiwan
  • Thailand
  • Trinidad and Tobago
  • Turks and Caicos Islands
  • Ukraine
  • United Arab Emirates
  • United Kingdom
  • United States
  • Uruguay
  • Vietnam
  • Virgin Islands (U.S.)
  • West Bank and Gaza

Typical traffic

For the following countries, the returned ETA is calculated using typical traffic data along the requested route.

  • Afghanistan
  • Albania
  • Algeria
  • American Samoa
  • Angola
  • Azerbaijan
  • Bangladesh
  • Belize
  • Benin
  • Bhutan
  • Bolivia
  • Bosnia and Herzegovina
  • Botswana
  • Burkina Faso
  • Burundi
  • Cabo Verde
  • Cameroon
  • Central African Republic
  • Chad
  • Comoros
  • Congo, Dem. Rep.
  • Congo, Rep.
  • Cote d'Ivoire
  • Croatia
  • Cuba
  • Djibouti
  • Dominica
  • Egypt, Arab Rep.
  • Equatorial Guinea
  • Eswatini
  • Ethiopia
  • Fiji
  • French Polynesia
  • Gabon
  • Gambia, The
  • Georgia
  • Ghana
  • Greece
  • Greenland
  • Guinea
  • Guinea-Bissau
  • Guyana
  • Haiti
  • Honduras
  • Iceland
  • India
  • Iraq
  • Jamaica
  • Kazakhstan
  • Kenya
  • Kiribati
  • Lao PDR
  • Lesotho
  • Liberia
  • Libya
  • Lithuania
  • Madagascar
  • Malawi
  • Mali
  • Marshall Islands
  • Mauritania
  • Mauritius
  • Micronesia, Fed. Sts.
  • Mongolia
  • Morocco
  • Mozambique
  • Myanmar
  • Namibia
  • Nepal
  • New Caledonia
  • Nicaragua
  • Niger
  • Nigeria
  • North Macedonia
  • Oman
  • Pakistan
  • Papua New Guinea
  • Paraguay
  • Philippines
  • Portugal
  • Rwanda
  • Samoa
  • Sao Tome and Principe
  • Senegal
  • Seychelles
  • Sierra Leone
  • Solomon Islands
  • Somalia
  • South Africa
  • Sri Lanka
  • Sudan
  • Suriname
  • Syrian Arab Republic
  • Tajikistan
  • Tanzania
  • Timor-Leste
  • Togo
  • Tonga
  • Tunisia
  • Turkey
  • Turkmenistan
  • Uganda
  • Uzbekistan
  • Vanuatu
  • Venezuela, RB
  • Yemen, Rep.
  • Zambia
  • Zimbabwe

Using directions services

There are many tools you can use to enable directions-related services for your Mapbox web or mobile application. You can access these services directly using the web services APIs, through our Navigation SDK, or using one of several plugins and libraries to integrate these services into applications across platforms.

Web services APIs

Mapbox offers five directions-related services:

  • Mapbox Directions API: retrieve point to point directions including a route with durations, estimated distances, and turn-by-turn instructions.
  • Mapbox Matrix API: retrieve all travel times between many points.
  • Mapbox Isochrone API: compute areas that are reachable within a specified amount of time from a location.
  • Mapbox Optimization API: retrieve duration-optimized trips between input coordinates.
  • Mapbox Map Matching API: align existing fuzzy routes to the routeable network.

Read more about the required inputs for each API below.

Mapbox Directions API

Requesting directions from the Mapbox Directions API requires at least two waypoints — an origin and a destination — but can also include up to 23 additional waypoints between (or a total of 25 waypoints). When making a request, you can specify additional parameters such as which routing profile to use (walking, cycling, driving, or driving with traffic) and whether alternate routes should be included in the response.

You can also add optional annotations to your request, including duration, distance, speed, and congestion. We calculate congestion by comparing night-time traffic speeds with real-time traffic speeds and assign a level of congestion given the percentage difference.

You can read more about the directions response object in our Directions API documentation.

Use of the Directions API is billed by API requests. For more details, see the Directions API pricing page.

Mapbox Matrix API

The Mapbox Matrix API returns travel times between many locations. Each location is either a source or destination. The number of sources and destinations are multiplied to create the matrix, or timetable, and calculate the number of elements needed to make the request. For example, given three locations A, B, C, the Matrix API will return a matrix of all travel times in seconds between all locations:

ABC
AA → AA → BA → C
BB → AB → BB → C
CC → AC → BC → C

The Matrix API will always return the duration on the most efficient route for each location in the matrix, where an element is an origin-destination pair in the matrix.

Durations between locations may not be symmetric (for example A to B may have a different duration than B to A), as the routes may differ by direction due to one-way streets or turn restrictions. By default the Matrix API returns durations in seconds, but it can also return route distances if specified in the annotations parameter. Like the Directions API, the Matrix API must be used within a single continent (the inputs must not require it to cross over water bodies).

This API allows you to build tools that efficiently check the reachability of coordinates from each other, filter locations by travel time, or run your own algorithms for solving optimization problems.

Matrix API requests

Each request requires that you specify which locations are the sources and which are the destinations. There are four types of requests you can use with the Matrix API:

Many to many (NxN)

A many to many request is the default and generates the most results per-number-of-coordinates. This assumes all locations are sources and destinations. Without passing the source and destinations in the request, the response will still output an array of travel times between all locations.

https://api.mapbox.com/directions-matrix/v1/mapbox/driving/A;B;C;D;E?access_token=...

One to many (1xN)

In some cases, you may have a single source (for example, one driver) and four potential destinations (four gas stations). To calculate which destination has the shortest drive time, you need to specify the source and destination coordinates.

https://api.mapbox.com/directions-matrix/v1/mapbox/driving/A;B;C;D;E?sources=0&destinations=1;2;3;4&access_token=...

Many to one (Nx1)

An opposite request may be necessary where you may want to find travel times of many taxis to one rider, for example. In this case, you can make a many-to-one (Nx1) request by listing all your sources and your one destination.

https://api.mapbox.com/directions-matrix/v1/mapbox/driving/A;B;C;D;E?sources=1;2;3;4&destinations=0&access_token=...

Several to several (MxN)

An uncommon but useful case is a several to several (NxM) request where you may want to be selective about how many sources and destinations you wish to find travel times to and from.

https://api.mapbox.com/directions-matrix/v1/mapbox/driving/A;B;C;D;E?sources=0;1&destinations=2;3;4&access_token=...

Use of the Matrix API is billed by the number of elements returned by a request. For more details, see the Matrix API pricing page.

Mapbox Isochrone API

The Mapbox Isochrone API computes areas that are reachable within a specified amount of time from a location, and returns the reachable regions as contours of polygons or lines that you can display on a map. This API also supports contours based on distance.

With the Isochrone API, you can calculate isochrones of up to 60 minutes or 100 kilometers using driving, driving-traffic, cycling, or walking profiles, define delivery or service zones based on travel times from a starting location, illustrate travel times on a map with lines or polygons, or create geofences to trigger location-aware user experiences, notifications, or events.

Use of the Isochrone API is billed by API requests. For more details, see the Isochrone API pricing page.

Mapbox Optimization API

The Mapbox Optimization API returns a duration-optimized trip between the input coordinates. This is also known as solving the Traveling Salesperson Problem. This API could be used to plan a route for deliveries in a city. Optimized trips can be retrieved for driving, bicycling, and walking or hiking.

optimized trips

Use of the Optimization API is billed by API requests. For more details, see the Optimization API pricing page.

Mapbox Map Matching API

The Mapbox Map Matching API snaps fuzzy, inaccurate traces from a GPS unit or a phone to the OpenStreetMap road and path network using the Directions API. This produces clean paths that can be displayed on a map or used for other analysis.

map matching

Use of the Map Matching API is billed by API requests. For more details, see the Map Matching API pricing page.

Mapbox Navigation SDK

You can add directions to a mobile application using the Mapbox Navigation SDK for iOS and Android. With the Navigation SDK, it takes only a few lines of code to display a complete navigation experience inside your app. With the Navigation SDK, you can:

  • Generate turn-by-turn instructions.
  • Use automatic rerouting when a user deviates from the route.
  • Provide walking, biking, and driving directions.
  • Provide real-time traffic.

Read more about the Navigation SDK for iOS and Android.

Libraries and plugins

We have several tools across platforms that allow you to integrate the Mapbox Directions API into your existing applications seamlessly:

These tools allow you to add routing capabilities to your application, but have limitations when it comes to customization. These tools do not provide access to the Mapbox Matrix API, Optimization API, or Map Matching API. For more flexibility, you can use our APIs directly or using our JavaScript library.

Here's an example of the Mapbox GL Directions plugin in action:

Testing the Directions API

If you would like to get a feel for how the Mapbox Directions API works without building a whole application, we also provide a Directions API Playground. Besides providing a convenient user interface to test queries, the API playground allows you to test the API's URL and query parameters, such as mode of transportation, steps, and alternative routes.

Visit the API Playgroundchevron-right

Providing directions feedback

To report routing issues you've identified with the Directions API, you can provide feedback from our Directions API Playground by generating the route and then clicking the Send feedback about this route button. For all other navigation-related services, contact our Support team with the full API request.

Was this page helpful?