Navigation | Directions API | Overview | 2GIS Documentation

Directions API

The Directions API allows you to plot a route on the map from one point to another. The Directions API can build the following types of routes:

  • a route for a car with information about traffic jams based on the real-time or statistical data
  • a route for a car avoiding toll and dirt roads, if this option was chosen when building the route
  • a route for a car taking public transport lanes into account
  • a pedestrian route with information about crosswalks and obstacles
  • a route from point A to point B with up to 10 intermediate stops, including start and end points

Requests are made using the POST method, all required parameters should be passed in the JSON format. The responses are also generated in the JSON format.

The request takes the coordinates of the route points. You will receive the geometry and length of the route and estimated travel time in response. All request and response parameters are listed in the API Reference.

To plot a route select the start and end points on the map.

<!DOCTYPE html>
<html lang="en">
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>2GIS Navi API</title>
        <meta name="description" content="Navi API directions example" />
            #container {
                margin: 0;
                width: 100%;
                height: 100%;
                overflow: hidden;
            #reset {
                padding: 4px 10px;
                background: #00a81f;
                border-radius: 4px;
                box-shadow: 0 1px 3px 0 rgba(38, 38, 38, 0.5);
                border: none;
                color: #fff;
                font-size: 12px;
                cursor: pointer;
        <div id="container"></div>
        <script src=""></script>
        <script src="^2/dist/directions.js"></script>
            const map = new mapgl.Map('container', {
                center: [55.31878, 25.23584],
                zoom: 13,
                key: 'Your API access key',

            const directions = new mapgl.Directions(map, {
                // This key can be used for demo purpose only!
                // You can get your own key on
                directionsApiKey: 'Your directions API access key',
            const markers = [];

            let firstPoint;
            let secondPoint;
            // A current selecting point
            let selecting = 'a';

            const controlsHtml = `<button id="reset">Сбросить точки</button> `;
            new mapgl.Control(map, controlsHtml, {
                position: 'topLeft',
            const resetButton = document.getElementById('reset');

            resetButton.addEventListener('click', function() {
                selecting = 'a';
                firstPoint = undefined;
                secondPoint = undefined;

            map.on('click', (e) => {
                const coords = e.lngLat;

                if (selecting != 'end') {
                    // Just to visualize selected points, before the route is done
                        new mapgl.Marker(map, {
                            coordinates: coords,
                            icon: '',

                if (selecting === 'a') {
                    firstPoint = coords;
                    selecting = 'b';
                } else if (selecting === 'b') {
                    secondPoint = coords;
                    selecting = 'end';

                // If all points are selected — we can draw the route
                if (firstPoint && secondPoint) {
                        points: [firstPoint, secondPoint],
                    markers.forEach((m) => {

To retrieve route data make a POST request to with Content-Type application/json.

The request takes the following parameters:

  • key=YOUR_KEY — your API key
    "locale": "en",
    "point_a_name": "Source",
    "point_b_name": "Target",
    "points": [
            "type": "pedo",
            "x": 82.93057,
            "y": 54.943207
            "object_id": "141476222741292",
            "type": "pedo",
            "x": 82.945039,
            "y": 55.033879
    "type": "jam"
    "query": {
      "locale": "en",
      "point_a_name": "Source",
      "point_b_name": "Target",
      "points": [],
      "type": "jam"
    "result": [
        "algorithm": "including traffic jams",
        "begin_pedestrian_path": {...},
        "end_pedestrian_path": {...},
        "filter_road_types": [...],
        "id": "1805336109018823561",
        "maneuvers": [...],
        "route_id": "em9.n3/carrouting/1588235082.031",
        "total_distance": 15153,
        "total_duration": 2204,
        "type": "carrouting",
        "ui_total_distance": {},
        "ui_total_duration": "36 min",
        "waypoints": [...]
    "type": "string"
  1. Fill in the application form to get your key.
  2. Learn about the request and response formats.