Matrix Routing is a PTV feature to compute distance and travel time matrix.
Using the Matrix Routing API is simple. Follow the steps on this page to get started with matrix calculation. For an easy integration you can also use the clients for Java, C# and TypeScript on GitHub.
Please note the individual rate and request limits for each API. You can find all limits in our FAQ.
Request
Use the following endpoint via POST to start the computation.
https://api.myptv.com/matrixrouting/v1/matrices
The following simple request is to be inserted into the request body in JSON representation.
{
"origins": [
{"longitude":8.4274,"latitude":49.0138},
{"longitude":8.4274,"latitude":49.1138},
{"longitude":8.4274,"latitude":49.2138}
]
}
You can test the simple request by choosing one of the following options.
cURL:
curl --location --request POST "https://api.myptv.com/matrixrouting/v1/matrices" --header "Content-Type: application/json" --header "ApiKey: YOUR_API_KEY" --data-raw "{ \"origins\": [ { \"longitude\":8.4274, \"latitude\":49.0138},{\"longitude\":8.4274, \"latitude\":49.1138}, {\"longitude\":8.4274, \"latitude\":49.2138} ] }"
PowerShell:
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("ApiKey", "YOUR_API_KEY")
$headers.Add("Content-Type", "application/json")
$body='{ "origins": [ { "longitude":8.4274, "latitude":49.0138 }, { "longitude":8.4274, "latitude":49.1138 }, { "longitude":8.4274, "latitude":49.2138 } ] }'
try
{
$response = Invoke-RestMethod 'https://api.myptv.com/matrixrouting/v1/matrices' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json -Depth 10
}
catch
{
$streamReader = [System.IO.StreamReader]::new($_.Exception.Response.GetResponseStream())
$streamReader.ReadToEnd() | ConvertFrom-Json
$streamReader.Close()
}
Response
Below you will find a possible result.
The response contains the distance and travel times between locations
{
"travelTimes": [
0,
1285,
2266,
1316,
0,
1232,
2200,
1232,
0
]
}