Route - Post Route Matrix

Applies to: see pricing tiers.

The Matrix Routing service allows calculation of a matrix of route summaries for a set of routes defined by origin and destination locations by using an asynchronous (async) or synchronous (sync) POST request. For every given origin, the service calculates the cost of routing from that origin to every given destination. The set of origins and the set of destinations can be thought of as the column and row headers of a table and each cell in the table contains the costs of routing from the origin to the destination for that cell. As an example, let's say a food delivery company has 20 drivers and they need to find the closest driver to pick up the delivery from the restaurant. To solve this use case, they can call Matrix Route API.

For each route, the travel times and distances are returned. You can use the computed costs to determine which detailed routes to calculate using the Route Directions API.

The maximum size of a matrix for async request is 700 and for sync request it's 100 (the number of origins multiplied by the number of destinations).

Submit Synchronous Route Matrix Request

If your scenario requires synchronous requests and the maximum size of the matrix is less than or equal to 100, you might want to make synchronous request. The maximum size of a matrix for this API is 100 (the number of origins multiplied by the number of destinations). With that constraint in mind, examples of possible matrix dimensions are: 10x10, 6x8, 9x8 (it does not need to be square).

POST https://atlas.microsoft.com/route/matrix/sync/json?api-version=1.0&subscription-key={subscription-key}

Submit Asynchronous Route Matrix Request

The Asynchronous API is appropriate for processing big volumes of relatively complex routing requests. When you make a request by using async request, by default the service returns a 202 response code along a redirect URL in the Location field of the response header. This URL should be checked periodically until the response data or error information is available. If waitForResults parameter in the request is set to true, user will get a 200 response if the request is finished under 120 seconds.

The maximum size of a matrix for this API is 700 (the number of origins multiplied by the number of destinations). With that constraint in mind, examples of possible matrix dimensions are: 50x10, 10x10, 28x25. 10x70 (it does not need to be square).

The asynchronous responses are stored for 14 days. The redirect URL returns a 404 response if used after the expiration period.

POST https://atlas.microsoft.com/route/matrix/json?api-version=1.0&subscription-key={subscription-key}

Here's a typical sequence of asynchronous operations:

  1. Client sends a Route Matrix POST request to Azure Maps

  2. The server will respond with one of the following:

    HTTP 202 Accepted - Route Matrix request has been accepted.

    HTTP Error - There was an error processing your Route Matrix request. This could either be a 400 Bad Request or any other Error status code.

  3. If the Matrix Route request was accepted successfully, the Location header in the response contains the URL to download the results of the request. This status URI looks like the following:

  GET https://atlas.microsoft.com/route/matrix/{matrixId}?api-version=1.0?subscription-key={subscription-key}
  1. Client issues a GET request on the download URL obtained in Step 3 to download the results

Download Sync Results

When you make a POST request for Route Matrix Sync API, the service returns 200 response code for successful request and a response array. The response body will contain the data and there will be no possibility to retrieve the results later.

Download Async Results

When a request issues a 202 Accepted response, the request is being processed using our async pipeline. You will be given a URL to check the progress of your async request in the location header of the response. This status URI looks like the following:

  GET https://atlas.microsoft.com/route/matrix/{matrixId}?api-version=1.0?subscription-key={subscription-key}

The URL provided by the location header will return the following responses when a GET request is issued.

HTTP 202 Accepted - Matrix request was accepted but is still being processed. Please try again in some time.

HTTP 200 OK - Matrix request successfully processed. The response body contains all of the results.

POST https://atlas.microsoft.com/route/matrix/json?api-version=1.0
POST https://atlas.microsoft.com/route/matrix/json?api-version=1.0&waitForResults={waitForResults}&computeTravelTimeFor={computeTravelTimeFor}&sectionType={sectionType}&arriveAt={arriveAt}&departAt={departAt}&vehicleAxleWeight={vehicleAxleWeight}&vehicleLength={vehicleLength}&vehicleHeight={vehicleHeight}&vehicleWidth={vehicleWidth}&vehicleMaxSpeed={vehicleMaxSpeed}&vehicleWeight={vehicleWeight}&windingness={windingness}&hilliness={hilliness}&travelMode={travelMode}&avoid={avoid}&traffic={traffic}&routeType={routeType}&vehicleLoadType={vehicleLoadType}

URI Parameters

Name In Required Type Description
format
path True

Desired format of the response. Only json format is supported.

api-version
query True
  • string

Version number of Azure Maps API.

arriveAt
query
  • string
date-time

The date and time of arrival at the destination point. It must be specified as a dateTime. When a time zone offset is not specified it will be assumed to be that of the destination point. The arriveAt value must be in the future. The arriveAt parameter cannot be used in conjunction with departAt, minDeviationDistance or minDeviationTime.

avoid
query
  • array

Specifies something that the route calculation should try to avoid when determining the route. Can be specified multiple times in one request, for example, '&avoid=motorways&avoid=tollRoads&avoid=ferries'. In calculateReachableRange requests, the value alreadyUsedRoads must not be used.

computeTravelTimeFor
query

Specifies whether to return additional travel times using different types of traffic information (none, historic, live) as well as the default best-estimate travel time.

departAt
query
  • string
date-time

The date and time of departure from the origin point. Departure times apart from now must be specified as a dateTime. When a time zone offset is not specified, it will be assumed to be that of the origin point. The departAt value must be in the future in the date-time format (1996-12-19T16:39:57-08:00).

hilliness
query

Degree of hilliness for thrilling route. This parameter can only be used in conjunction with routeType=thrilling.

routeType
query

The type of route requested.

sectionType
query

Specifies which of the section types is reported in the route response.

For example if sectionType = pedestrian the sections which are suited for pedestrians only are returned. Multiple types can be used. The default sectionType refers to the travelMode input. By default travelMode is set to car

traffic
query
  • boolean

Possible values:

  • true - Do consider all available traffic information during routing
  • false - Ignore current traffic data during routing. Note that although the current traffic data is ignored during routing, the effect of historic traffic on effective road speeds is still incorporated.
travelMode
query

The mode of travel for the requested route. If not defined, default is 'car'. Note that the requested travelMode may not be available for the entire route. Where the requested travelMode is not available for a particular section, the travelMode element of the response for that section will be "other". Note that travel modes bus, motorcycle, taxi and van are BETA functionality. Full restriction data is not available in all areas. In calculateReachableRange requests, the values bicycle and pedestrian must not be used.

vehicleAxleWeight
query
  • integer

Weight per axle of the vehicle in kg. A value of 0 means that weight restrictions per axle are not considered.

vehicleHeight
query
  • number
double

Height of the vehicle in meters. A value of 0 means that height restrictions are not considered.

vehicleLength
query
  • number
double

Length of the vehicle in meters. A value of 0 means that length restrictions are not considered.

vehicleLoadType
query

Types of cargo that may be classified as hazardous materials and restricted from some roads. Available vehicleLoadType values are US Hazmat classes 1 through 9, plus generic classifications for use in other countries. Values beginning with USHazmat are for US routing while otherHazmat should be used for all other countries. vehicleLoadType can be specified multiple times. This parameter is currently only considered for travelMode=truck.

vehicleMaxSpeed
query
  • integer

Maximum speed of the vehicle in km/hour. The max speed in the vehicle profile is used to check whether a vehicle is allowed on motorways.

  • A value of 0 means that an appropriate value for the vehicle will be determined and applied during route planning.

  • A non-zero value may be overridden during route planning. For example, the current traffic flow is 60 km/hour. If the vehicle maximum speed is set to 50 km/hour, the routing engine will consider 60 km/hour as this is the current situation. If the maximum speed of the vehicle is provided as 80 km/hour but the current traffic flow is 60 km/hour, then routing engine will again use 60 km/hour.

vehicleWeight
query
  • integer

Weight of the vehicle in kilograms.

vehicleWidth
query
  • number
double

Width of the vehicle in meters. A value of 0 means that width restrictions are not considered.

waitForResults
query
  • boolean

Boolean to indicate whether to execute the request synchronously. If set to true, user will get a 200 response if the request is finished under 120 seconds. Otherwise, user will get a 202 response right away. Please refer to the API description for more details on 202 response. Supported only for async request.

windingness
query

Level of turns for thrilling route. This parameter can only be used in conjunction with routeType=thrilling.

Request Header

Name Required Type Description
x-ms-client-id
  • string

Specifies which account is intended for usage in conjunction with the Azure AD security model. It represents a unique ID for the Azure Maps account and can be retrieved from the Azure Maps management plane Account API. To use Azure AD security in Azure Maps see the following articles for guidance.

Request Body

Name Type Description
destinations

A valid GeoJSON MultiPoint geometry type. Please refer to RFC 7946 for details.

origins

A valid GeoJSON MultiPoint geometry type. Please refer to RFC 7946 for details.

Responses

Name Type Description
200 OK

Matrix request successfully processed. The response body contains all of the results.

202 Accepted

Supported only for async request. Request Accepted: The request has been accepted for processing. Please use the URL in the Location Header to retry or access the results.

Headers

  • Location: string
Other Status Codes

An unexpected error occurred.

Security

AADToken

These are the Azure Active Directory OAuth2 Flows. When paired with Azure role-based access control it can be used to control access to Azure Maps REST APIs. Azure role-based access controls are used to designate access to one or more Azure Maps resource account or sub-resources. Any user, group, or service principal can be granted access via a built-in role or a custom role composed of one or more permissions to Azure Maps REST APIs.

To implement scenarios, we recommend viewing authentication concepts. In summary, this security definition provides a solution for modeling application(s) via objects capable of access control on specific APIs and scopes.

Notes

  • This security definition requires the use of the x-ms-client-id header to indicate which Azure Maps resource the application is requesting access to. This can be acquired from the Maps management API.

The Authorization URL is specific to the Azure public cloud instance. Sovereign clouds have unique Authorization URLs and Azure Active directory configurations. * The Azure role-based access control is configured from the Azure management plane via Azure portal, PowerShell, CLI, Azure SDKs, or REST APIs. * Usage of the Azure Maps Web SDK allows for configuration based setup of an application for multiple use cases.

  • Currently, Azure Active Directory v1.0 or v2.0 supports Work, School, and Guests but does not support Personal accounts.

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Scopes

Name Description
https://atlas.microsoft.com/.default https://atlas.microsoft.com/.default

subscription-key

This is a shared key that is provisioned when creating an Azure Maps resource through the Azure management plane via Azure portal, PowerShell, CLI, Azure SDKs, or REST APIs.

With this key, any application is authorized to access all REST APIs. In other words, these can currently be treated as master keys to the account which they are issued for.

For publicly exposed applications, our recommendation is to use server-to-server access of Azure Maps REST APIs where this key can be securely stored.

Type: apiKey
In: query

SAS Token

This is a shared access signature token is created from the List SAS operation on the Azure Maps resource through the Azure management plane via Azure portal, PowerShell, CLI, Azure SDKs, or REST APIs.

With this token, any application is authorized to access with Azure role-based access controls and fine-grain control to the expiration, rate, and region(s) of use for the particular token. In other words, the SAS Token can be used to allow applications to control access in a more secured way than the shared key.

For publicly exposed applications, our recommendation is to configure a specific list of allowed origins on the Map account resource to limit rendering abuse and regularly renew the SAS Token.

Type: apiKey
In: header

Examples

Successfully submit a route matrix request

Sample Request

POST https://atlas.microsoft.com/route/matrix/json?api-version=1.0&routeType=shortest
{
  "origins": {
    "type": "MultiPoint",
    "coordinates": [
      [
        4.85106,
        52.36006
      ],
      [
        4.85056,
        52.36187
      ]
    ]
  },
  "destinations": {
    "type": "MultiPoint",
    "coordinates": [
      [
        4.85003,
        52.36241
      ],
      [
        13.42937,
        52.50931
      ]
    ]
  }
}

Sample Response

{
  "formatVersion": "0.0.1",
  "matrix": [
    [
      {
        "statusCode": 200,
        "response": {
          "routeSummary": {
            "lengthInMeters": 495,
            "travelTimeInSeconds": 134,
            "trafficDelayInSeconds": 0,
            "departureTime": "2018-07-27T22:55:29+00:00",
            "arrivalTime": "2018-07-27T22:57:43+00:00"
          }
        }
      },
      {
        "statusCode": 200,
        "response": {
          "routeSummary": {
            "lengthInMeters": 647651,
            "travelTimeInSeconds": 26835,
            "trafficDelayInSeconds": 489,
            "departureTime": "2018-07-27T22:55:29+00:00",
            "arrivalTime": "2018-07-28T06:22:44+00:00"
          }
        }
      }
    ],
    [
      {
        "statusCode": 200,
        "response": {
          "routeSummary": {
            "lengthInMeters": 338,
            "travelTimeInSeconds": 104,
            "trafficDelayInSeconds": 0,
            "departureTime": "2018-07-27T22:55:29+00:00",
            "arrivalTime": "2018-07-27T22:57:13+00:00"
          }
        }
      },
      {
        "statusCode": 200,
        "response": {
          "routeSummary": {
            "lengthInMeters": 647494,
            "travelTimeInSeconds": 26763,
            "trafficDelayInSeconds": 469,
            "departureTime": "2018-07-27T22:55:29+00:00",
            "arrivalTime": "2018-07-28T06:21:32+00:00"
          }
        }
      }
    ]
  ],
  "summary": {
    "successfulRoutes": 4,
    "totalRoutes": 4
  }
}
Location: New URL to check the status of the long running request.

Definitions

ComputeTravelTime

Specifies whether to return additional travel times using different types of traffic information (none, historic, live) as well as the default best-estimate travel time.

ErrorAdditionalInfo

The resource management error additional info.

ErrorDetail

The error detail.

ErrorResponse

Error response

GeoJsonMultiPoint

A valid GeoJSON MultiPoint geometry type. Please refer to RFC 7946 for details.

InclineLevel

Degree of hilliness for thrilling route. This parameter can only be used in conjunction with routeType=thrilling.

JsonFormat

Desired format of the response. Only json format is supported.

RouteMatrixQuery

An object with a matrix of coordinates.

RouteMatrixResult

This object is returned from a successful Route Matrix call. For ex, if 2 origins and 3 destinations are provided, there are going to 2 arrays with 3 elements in each. Each element's content depends on the options provided in the query.

RouteMatrixSummary

Summary object

RouteType

The type of route requested.

SectionType

Specifies which of the section types is reported in the route response.

For example if sectionType = pedestrian the sections which are suited for pedestrians only are returned. Multiple types can be used. The default sectionType refers to the travelMode input. By default travelMode is set to car

TravelMode

The mode of travel for the requested route. If not defined, default is 'car'. Note that the requested travelMode may not be available for the entire route. Where the requested travelMode is not available for a particular section, the travelMode element of the response for that section will be "other". Note that travel modes bus, motorcycle, taxi and van are BETA functionality. Full restriction data is not available in all areas. In calculateReachableRange requests, the values bicycle and pedestrian must not be used.

VehicleLoadType

Types of cargo that may be classified as hazardous materials and restricted from some roads. Available vehicleLoadType values are US Hazmat classes 1 through 9, plus generic classifications for use in other countries. Values beginning with USHazmat are for US routing while otherHazmat should be used for all other countries. vehicleLoadType can be specified multiple times. This parameter is currently only considered for travelMode=truck.

WindingnessLevel

Level of turns for thrilling route. This parameter can only be used in conjunction with routeType=thrilling.

ComputeTravelTime

Specifies whether to return additional travel times using different types of traffic information (none, historic, live) as well as the default best-estimate travel time.

Name Type Description
all
  • string

Computes travel times for all types of traffic information and specifies all results in the fields noTrafficTravelTimeInSeconds, historicTrafficTravelTimeInSeconds and liveTrafficIncidentsTravelTimeInSeconds being included in the summaries in the route response.

none
  • string

Does not compute additional travel times.

ErrorAdditionalInfo

The resource management error additional info.

Name Type Description
info
  • object

The additional info.

type
  • string

The additional info type.

ErrorDetail

The error detail.

Name Type Description
additionalInfo

The error additional info.

code
  • string

The error code.

details

The error details.

message
  • string

The error message.

target
  • string

The error target.

ErrorResponse

Error response

Name Type Description
error

The error object.

GeoJsonMultiPoint

A valid GeoJSON MultiPoint geometry type. Please refer to RFC 7946 for details.

Name Type Description
coordinates
  • array[]

Coordinates for the GeoJson MultiPoint geometry.

type string:
  • MultiPoint

Specifies the GeoJSON type. Must be one of the nine valid GeoJSON object types - Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, GeometryCollection, Feature and FeatureCollection.

InclineLevel

Degree of hilliness for thrilling route. This parameter can only be used in conjunction with routeType=thrilling.

Name Type Description
high
  • string

high

low
  • string

low

normal
  • string

normal

JsonFormat

Desired format of the response. Only json format is supported.

Name Type Description
json
  • string

The JavaScript Object Notation Data Interchange Format

RouteMatrixQuery

An object with a matrix of coordinates.

Name Type Description
destinations

A valid GeoJSON MultiPoint geometry type. Please refer to RFC 7946 for details.

origins

A valid GeoJSON MultiPoint geometry type. Please refer to RFC 7946 for details.

RouteMatrixResult

This object is returned from a successful Route Matrix call. For ex, if 2 origins and 3 destinations are provided, there are going to 2 arrays with 3 elements in each. Each element's content depends on the options provided in the query.

Name Type Description
formatVersion
  • string

Format Version property

matrix
  • array[]

Results as a 2 dimensional array of route summaries.

summary

Summary object

RouteMatrixSummary

Summary object

Name Type Description
successfulRoutes
  • integer

Number of successful routes in the response.

totalRoutes
  • integer

Total number of routes requested. Number of cells in the input matrix.

RouteType

The type of route requested.

Name Type Description
eco
  • string

A route balanced by economy and speed.

fastest
  • string

The fastest route.

shortest
  • string

The shortest route by distance.

thrilling
  • string

Includes interesting or challenging roads and uses as few motorways as possible. You can choose the level of turns included and also the degree of hilliness. See the hilliness and windingness parameters for how to set this. There is a limit of 900 km on routes planned with routeType=thrilling

SectionType

Specifies which of the section types is reported in the route response.

For example if sectionType = pedestrian the sections which are suited for pedestrians only are returned. Multiple types can be used. The default sectionType refers to the travelMode input. By default travelMode is set to car

Name Type Description
carTrain
  • string

Sections of the route that are cars or trains.

carpool
  • string

Sections of the route that require use of carpool (HOV/High Occupancy Vehicle) lanes.

country
  • string

Sections indicating which countries the route is in.

ferry
  • string

Sections of the route that are ferries.

motorway
  • string

Sections of the route that are motorways.

pedestrian
  • string

Sections of the route that are only suited for pedestrians.

tollRoad
  • string

Sections of the route that require a toll to be payed.

tollVignette
  • string

Sections of the route that require a toll vignette to be present.

traffic
  • string

Sections of the route that contain traffic information.

travelMode
  • string

Sections in relation to the request parameter travelMode.

tunnel
  • string

Sections of the route that are tunnels.

urban
  • string

Sections of the route that are located within urban areas.

TravelMode

The mode of travel for the requested route. If not defined, default is 'car'. Note that the requested travelMode may not be available for the entire route. Where the requested travelMode is not available for a particular section, the travelMode element of the response for that section will be "other". Note that travel modes bus, motorcycle, taxi and van are BETA functionality. Full restriction data is not available in all areas. In calculateReachableRange requests, the values bicycle and pedestrian must not be used.

Name Type Description
bicycle
  • string

The returned routes are optimized for bicycles, including use of bicycle lanes.

bus
  • string

The returned routes are optimized for buses, including the use of bus only lanes. BETA functionality.

car
  • string

The returned routes are optimized for cars.

motorcycle
  • string

The returned routes are optimized for motorcycles. BETA functionality.

pedestrian
  • string

The returned routes are optimized for pedestrians, including the use of sidewalks.

taxi
  • string

The returned routes are optimized for taxis. BETA functionality.

truck
  • string

The returned routes are optimized for commercial vehicles, like for trucks.

van
  • string

The returned routes are optimized for vans. BETA functionality.

VehicleLoadType

Types of cargo that may be classified as hazardous materials and restricted from some roads. Available vehicleLoadType values are US Hazmat classes 1 through 9, plus generic classifications for use in other countries. Values beginning with USHazmat are for US routing while otherHazmat should be used for all other countries. vehicleLoadType can be specified multiple times. This parameter is currently only considered for travelMode=truck.

Name Type Description
USHazmatClass1
  • string

Explosives

USHazmatClass2
  • string

Compressed gas

USHazmatClass3
  • string

Flammable liquids

USHazmatClass4
  • string

Flammable solids

USHazmatClass5
  • string

Oxidizers

USHazmatClass6
  • string

Poisons

USHazmatClass7
  • string

Radioactive

USHazmatClass8
  • string

Corrosives

USHazmatClass9
  • string

Miscellaneous

otherHazmatExplosive
  • string

Explosives

otherHazmatGeneral
  • string

Miscellaneous

otherHazmatHarmfulToWater
  • string

Harmful to water

WindingnessLevel

Level of turns for thrilling route. This parameter can only be used in conjunction with routeType=thrilling.

Name Type Description
high
  • string

high

low
  • string

low

normal
  • string

normal