Route - Post Route Matrix
Use to get a route matrix showing the travel time and distance for all possible pairs in a list of origins and destinations, using an asynchronous request.
The Post Route Matrix
API is an HTTP POST
request that allows calculation of a matrix of route summaries for a set of routes defined by origin and destination locations by using an asynchronous (async) request. To make a synchronous (sync) request, see Post Route Matrix Sync. 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).
Note
All origins and destinations should be contained in an axis-aligned 400 km x 400 km bounding box. Otherwise some matrix cells will be resolved as OUT_OF_REGION.
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 24 hours. 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:
Client sends a Route Matrix POST request to Azure Maps
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.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}
- 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}§ionType={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 |
|
api-version
|
query | True |
string |
Version number of Azure Maps API. |
arrive
|
query |
string date-time |
The date and time of arrival at the destination point formatted as a Examples:
The |
|
avoid
|
query |
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 Route Range requests, the value alreadyUsedRoads must not be used. |
||
compute
|
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. |
||
depart
|
query |
string date-time |
The date and time of departure from the origin point formatted as a
Examples:
The |
|
hilliness
|
query |
Degree of hilliness for thrilling route. This parameter can only be used in conjunction with |
||
route
|
query |
The type of route requested. |
||
section
|
query |
Specifies which of the section types is reported in the route response. |
||
traffic
|
query |
boolean |
Possible values:
|
|
travel
|
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. |
||
vehicle
|
query |
integer |
Weight per axle of the vehicle in kg. A value of 0 means that weight restrictions per axle are not considered. |
|
vehicle
|
query |
number double |
Height of the vehicle in meters. A value of 0 means that height restrictions are not considered. |
|
vehicle
|
query |
number double |
Length of the vehicle in meters. A value of 0 means that length restrictions are not considered. |
|
vehicle
|
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/regions. Values beginning with USHazmat are for US routing while otherHazmat should be used for all other countries/regions. vehicleLoadType can be specified multiple times. This parameter is currently only considered for travelMode=truck. |
||
vehicle
|
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.
|
|
vehicle
|
query |
integer |
Weight of the vehicle in kilograms. |
|
vehicle
|
query |
number double |
Width of the vehicle in meters. A value of 0 means that width restrictions are not considered. |
|
wait
|
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 |
Request Header
Name | Required | Type | Description |
---|---|---|---|
x-ms-client-id |
string |
Specifies which account is intended for usage in conjunction with the Microsoft Entra ID 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 Microsoft Entra ID security in Azure Maps see the following articles for guidance. |
Request Body
Name | Type | Description |
---|---|---|
destinations |
A valid |
|
origins |
A valid |
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 Microsoft Entra OAuth 2.0 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 Microsoft Entra ID 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.
- For more information on Microsoft identity platform, see Microsoft identity platform overview.
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 you Create an Azure Maps account in the Azure portal or using PowerShell, CLI, Azure SDKs, or REST API.
With this key, any application can access all REST API. In other words, this key can be used as a master key in the account that they are issued in.
For publicly exposed applications, our recommendation is to use the confidential client applications approach to access Azure Maps REST APIs so your 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
}
}
operation-Location: New URL to check the status of the long-running operation.
Definitions
Name | Description |
---|---|
Compute |
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. |
Error |
The resource management error additional info. |
Error |
The error detail. |
Error |
Error response |
Geo |
A valid |
Incline |
Degree of hilliness for thrilling route. This parameter can only be used in conjunction with |
Json |
Desired format of the response. Only |
Route |
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 Route Range requests, the value alreadyUsedRoads must not be used. |
Route |
Summary object for route section. |
Route |
Matrix result object |
Route |
An object with a matrix of coordinates. |
Route |
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. |
Route |
Response object of the current cell in the input matrix. |
Route |
Summary object |
Route |
The type of route requested. |
Section |
Specifies which of the section types is reported in the route response. |
Travel |
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. |
Vehicle |
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/regions. Values beginning with USHazmat are for US routing while otherHazmat should be used for all other countries/regions. vehicleLoadType can be specified multiple times. This parameter is currently only considered for travelMode=truck. |
Windingness |
Level of turns for thrilling route. This parameter can only be used in conjunction with |
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 |
number[] |
Coordinates for the |
type |
string:
Multi |
Specifies the |
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 |
RouteAvoidType
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 Route Range requests, the value alreadyUsedRoads must not be used.
Name | Type | Description |
---|---|---|
alreadyUsedRoads |
string |
Avoids using the same road multiple times. Most useful in conjunction with |
borderCrossings |
string |
Avoids border crossings in route calculation. |
carpools |
string |
Avoids routes that require the use of carpool (HOV/High Occupancy Vehicle) lanes. |
ferries |
string |
Avoids ferries |
motorways |
string |
Avoids motorways |
tollRoads |
string |
Avoids toll roads. |
unpavedRoads |
string |
Avoids unpaved roads |
RouteLegSummary
Summary object for route section.
Name | Type | Description |
---|---|---|
arrivalTime |
string |
The estimated arrival time for the route or leg. Time is in UTC. |
batteryConsumptionInkWh |
number |
Estimated electric energy consumption in kilowatt hours (kWh) using the Electric Consumption Model. Included if vehicleEngineType is set to electric and constantSpeedConsumptionInkWhPerHundredkm is specified. The value of batteryConsumptionInkWh includes the recuperated electric energy and can therefore be negative (which indicates gaining energy). If both maxChargeInkWh and currentChargeInkWh are specified, recuperation will be capped to ensure that the battery charge level never exceeds maxChargeInkWh. If neither maxChargeInkWh nor currentChargeInkWh are specified, unconstrained recuperation is assumed in the consumption calculation. |
departureTime |
string |
The estimated departure time for the route or leg. Time is in UTC. |
fuelConsumptionInLiters |
number |
Estimated fuel consumption in liters using the Combustion Consumption Model. Included if vehicleEngineType is set to combustion and constantSpeedConsumptionInLitersPerHundredkm is specified. The value will be non-negative. |
historicTrafficTravelTimeInSeconds |
integer |
Estimated travel time calculated using time-dependent historic traffic data. Included only if computeTravelTimeFor = all is used in the query. |
lengthInMeters |
integer |
Length In Meters property |
liveTrafficIncidentsTravelTimeInSeconds |
integer |
Estimated travel time calculated using real-time speed data. Included only if computeTravelTimeFor = all is used in the query. |
noTrafficTravelTimeInSeconds |
integer |
Estimated travel time calculated as if there are no delays on the route due to traffic conditions (e.g. congestion). Included only if computeTravelTimeFor = all is used in the query. |
trafficDelayInSeconds |
integer |
Estimated delay in seconds caused by the real-time incident(s) according to traffic information. For routes planned with departure time in the future, delays is always 0. To return additional travel times using different types of traffic information, parameter computeTravelTimeFor=all needs to be added. |
travelTimeInSeconds |
integer |
Estimated travel time in seconds property that includes the delay due to real-time traffic. Note that even when traffic=false travelTimeInSeconds still includes the delay due to traffic. If DepartAt is in the future, travel time is calculated using time-dependent historic traffic data. |
RouteMatrix
Matrix result object
Name | Type | Description |
---|---|---|
response |
Response object of the current cell in the input matrix. |
|
statusCode |
integer |
StatusCode property for the current cell in the input matrix. |
RouteMatrixQuery
An object with a matrix of coordinates.
Name | Type | Description |
---|---|---|
destinations |
A valid |
|
origins |
A valid |
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 |
Results as a 2 dimensional array of route summaries. |
|
summary |
Summary object |
RouteMatrixResultResponse
Response object of the current cell in the input matrix.
Name | Type | Description |
---|---|---|
routeSummary |
Summary object for route section. |
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 |
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. Can be specified multiple times in one request, for example, '§ionType=carTrain§ionType=pedestrian§ionType=motorway'. 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/regions 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 paid. |
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 |
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.
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/regions. Values beginning with USHazmat are for US routing while otherHazmat should be used for all other countries/regions. 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 |