Documentation
Reference
2.1.50 (current version)
collection
interactivityModel
Interfaces

route

Static function.

Plots a route through the specified points.

Note. For the commercial version of the API, routing is available for the following countries: Russia, Ukraine, Belarus, Kazakhstan, Georgia, Abkhazia, South Ossetia, Armenia, Azerbaijan, Moldova, Turkmenistan, Tajikistan, Uzbekistan, Kyrgyzstan and Turkey.

Returns a promise object that is confirmed by the route object router.Route, or the multi-stop route object multiRouter.MultiRoute, depending on the value of the multiRoute parameter. If an error occurs, the promise object is rejected.

{ vow.Promise } route(points[, params])

Parameters:

ParameterDefault valueDescription
points*
[no-highlight[

* Mandatory parameter/option.

]no-highlight]

Type: Object[]

Array of points that the route should go through. Each point can be set by a string containing the address, an array of the coordinates, and a JSON object with the following fields:

  • type: String - Type of point. The 'wayPoint' value sets the route waypoint. Use the "viaPoint" value to define a throughpoint, i.e. a point that must be driven through without stopping.
  • point: Number[]|String - Array of the coordinates of a point, or its address as a string.

params

Type: Object

Routing options.

params.avoidTrafficJams false

Type: Boolean

Enables constructing a route with consideration for traffic. When using the options, keep in mind that it is not always possible to detour around traffic jams.

params.boundedBy

Type: Number[][]

Area on the map where the objects being searched for are presumably located. This is used if the route points are set using the mailing address instead of coordinates.

params.mapStateAutoApply false

Type: Boolean

Flag that allows to automatically set the center and map zoom so that the route will be entirely visible.

params.multiRoute false

Type: Boolean

Allows to construct multi-stop routes.

params.reverseGeocoding false

Type: Boolean

Whether to use reverse geocoding for points specified as coordinates.

params.routingMode "auto"

Type: String

Routing type. Accepts one of three string values:

  • "auto" - Driving route.
  • "masstransit" - Routing using public transit. Only for multi-stop routes (the multiRoute option must be set to true).
  • "pedestrian" - Walking route. Only for multi-stop routes (the multiRoute option must be set to true).

params.searchCoordOrder

Type: String

Defines how to interpret the coordinates in the request. This is used if the route points are set using coordinates, and not the mailing address.

params.strictBounds false

Type: Boolean

Search only inside the area defined by the "boundedBy" option.

params.useMapMargin true

Type: Boolean

Whether to account for map margins map.margin.Manager.

params.viaIndexes []

Type: Integer[]

Indexes of the multi-stop route throughpoints.

params.zoomMargin 0

Type: Number[][]|Number[]

Offset from the map viewport borders when changing the zoom level. If a single number is set, it is applied to each side. If two numbers are set, they are the horizontal and vertical margins, respectively. If an array of four numbers is set, they are the top, right, bottom, and left margins. When the "useMapMargin" parameter is enabled, the "zoomMargin" value is combined with the values that were calculated in the margins manager map.margin.Manager.

* Mandatory parameter/option.

Examples:

1.

// Building the route from Korolev to Krasnogorsk via Khimki and Mytischi,
// where Mytischi is a throughpoint. Setting coordinates for Krasnogorsk.
ymaps.route([
    'Korolev',
    { type: 'viaPoint', point: 'Mytischi' },
    'Himki',
    { type: 'wayPoint', point: [55.811511, 37.312518] }
], {
    mapStateAutoApply: true
}).then(function (route) {
    route.getPaths().options.set({
        // the balloon only shows information about the travel time with traffic
        balloonContentLayout: ymaps.templateLayoutFactory.createClass('{{ properties.humanJamsTime }}'),
        // you can make settings for route graphics
        strokeColor: '0000ffff',
        opacity: 0.9
    });
    // adding the route to the map
    map.geoObjects.add(route);
});

2.

// Building a multi-stop route and adding it to the map using autoscaling.
ymaps.route(['Southern Butovo', 'Moscow, metro Park Kultury'], {
    multiRoute: true
}).done(function (route) {
    route.options.set("mapStateAutoApply", true);
    myMap.geoObjects.add(route);
}, function (err) {
    throw err;
}, this);