This document will guide you through the different request and response parameters of Distance Matrix API and how you can extract data analogous to the Google Distance Matrix service from Distance Matrix API with the same accuracy, but for the more affordable and fair price.
Distance Matrix request
Google:
GET
https://maps.googleapis.com/maps/api/distancematrix/json?origins=<origin_location_1|origin_location_2|...|origin_location_n>&destinations=<destination_location_1|destination_location_2|...|destination_location_n>&key=<your_access_token>
https://api.distancematrix.ai/maps/api/distancematrix/json?origins=<origin_location_1|origin_location_2|...|origin_location_n>&destinations=<destination_location_1|destination_location_2|...|destination_location_n>&key=<your_access_token>
Distance Matrix example request
Google:
GET
https://maps.googleapis.com/maps/api/distancematrix/json?origins=51.4822656,-0.1933769&destinations=Westminster Abbey, Westminster, London SW1P 3PA, UK&key=<your_access_token>
https://api.distancematrix.ai/maps/api/distancematrix/json?origins=51.4822656,-0.1933769&destinations=Westminster Abbey, Westminster, London SW1P 3PA, UK&key=<your_access_token>
Required & Response parameters
Parameters in a request (part of the URL) is the same in both cases:
- list of origin locations (source <longitude,latitude> location coordinates or address) separated with vertical bar "|").
- list of destination locations (source <longitude,latitude> location coordinates or address) separated with vertical bar "|").
- key (your access token authorized to access the resource).
Response in JSON format (is the same in both cases):
- The unit of value of durations is second.
- The unit of value of distances is meter.
- Meant for car routing to get the duration considering live traffic.
- The coordinates pairs on which route is to be calculated. Minimum two pairs needed.
Distance Matrix example response
{
"destination_addresses": [
"Westminster Abbey, 20 Deans Yd, London SW1P 3PA, United Kingdom"
],
"origin_addresses": [
"Chapel, London SW6 1BA, UK"
],
"rows": [
{
"elements": [
{
"distance": {
"text": "7.8 km",
"value": 7847
},
"duration": {
"text": "24 mins",
"value": 1481
}
}
]
}
],
"status": "OK"
}
{
"destination_addresses": [
"Westminster Abbey, 20 Deans Yd, London SW1P 3PA, United Kingdom"
],
"origin_addresses": [
"Chapel, London SW6 1BA, UK"
],
"rows": [
{
"elements": [
{
"distance": {
"text": "7.8 km",
"value": 7847
},
"duration": {
"text": "24 mins",
"value": 1481
},
"origin": "51.4822656,-0.1933769",
"destination": "Westminster Abbey, Westminster, London SW1P 3PA, UK",
"status": "OK"
}
]
}
],
"status": "OK"
}