Route - Get 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.
The Get Route Matrix
API is an HTTP GET
request that computes the travel time and distance for all possible pairs in a list of origins and destinations. Unlike the Get Route Directions API, which provide detailed route instructions, this API focuses on efficiency by giving you the cost (travel time and distance) of routing from each origin to every destination. For more information, see Best practices for Azure Maps Route service.
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).
GET 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.
GET 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 GET 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 GET 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.
GET https://atlas.microsoft.com/route/matrix/{format}?api-version=1.0
URI Parameters
Name | In | Required | Type | Description |
---|---|---|---|---|
format
|
path | True |
string |
Matrix id received after the Matrix Route request was accepted successfully. |
api-version
|
query | True |
string |
Version number of Azure Maps API. |
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. |
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 retrieve the status for a route matrix request
Sample request
GET https://atlas.microsoft.com/route/matrix/11111111-2222-3333-4444-555555555555?api-version=1.0
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
}
}
Definitions
Name | Description |
---|---|
Error |
The resource management error additional info. |
Error |
The error detail. |
Error |
Error response |
Route |
Summary object for route section. |
Route |
Matrix result object |
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 |
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. |
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. |
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. |