Migrate to Distance Matrix AI

The Distance Matrix API

Introduction
This document will guide you through the different request and response parameters of DistanceMatrix API and how you can extract data analogous to the Google Distance Matrix service from DistanceMatrix API, the best Google Maps alternative.
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>
Distancematrix.ai:
GET
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>
Distancematrix.ai:
GET
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:
1. list of origin locations (source <longitude,latitude> location coordinates or address) separated with vertical bar "|").
2. list of destination locations (source <longitude,latitude> location coordinates or address) separated with vertical bar "|").
3. 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
Google:
GET
{
  "destination_addresses":["Westminster Abbey, Westminster, 
  London SW1P 3PA, UK"],
  "origin_addresses":["Chapel, Fulham, London SW6 1BA, UK"],
  "rows":[
    {
      "elements":[
        {
          "distance":{
            "text": "4.7 mi",
            "value": 7564
          },
          "duration":{
            "text": "28 mins",
            "value": 1680
          },
          "duration_in_traffic":{
            "text": "28 mins",
            "value": 1680
          },
          "status": "OK"
        }
      ]
    }
  ],
  "status": "OK"
}
Distancematrix.ai:
GET
{
  "destination_addresses":["Westminster Abbey, Westminster, 
  London SW1P 3PA, UK"],
  "origin_addresses":["Chapel, Fulham, London SW6 1BA, UK"],
  "rows":[
    {
      "elements":[
        {
          "distance":{
            "text": "4.7 miles",
            "value": 7563.898
          },
          "duration":{
            "text": "28 min",
            "value": 1680
          },
          "duration_in_traffic":{
            "text": "28 min",
            "value": 1680
          },
          "status": "OK"
        }
      ]
    }
  ],
  "status": "OK"
}
Do you need more information
about the Distance Matrix API?
Start a free 7-day trial of the Distance Matrix API for Business
No credit card required, cancel any time