Using the Time-Distance-Matrix

Our Time Distance Matrix is a high-performance time distance matrix API (1000*1000), that can be used for planning applications, which involve cars, trucks, bikes, pedestrians, field force technicians and mobile sales force a.o.

By entering up to 1000 origins and up to 1000 destinations, and using various routing options (shortest, fastest, safest, most efficient), the travel times and travel distances will be provided as a matrix, which can be used in  planning or routing applications.

In our examples, we will use Curl. If you’re on Linux or OS X, you will already have it installed.

Windows users can get it here. You can simply copy and paste the examples, but you will need to replace certain values with information that applies to your specific situation.

Let’s take you through some of the functionalities of the API through a step by step process.

Getting Started

GET YOUR FREE API KEY

First of all, you need to get some credentials. With an API key you will be able to access the related API and if applicable your usage will be automatically tracked and billed. Just click on the “GET YOUR FREE API KEY” button above, to apply for a free trial. Your API key will be between 30 and 128 characters long.

 

 

Get the Time Distance Data

The Time Distance Matrix needs to be accessed in two steps, first you need to send a json file containing the job parameters and you will receive a queue id. Second using the queue id, you can retrieve the current status of your batch job and the potential result.

Request a Batch Job

To request a new batch job, first create a json file. We will use this file as input for the curl request next.

{
    "result":["cost","distance"],
    "origin_addresses":["4.54270,51.91240"],
    "destination_addresses":["4.54260,51.91241","4.53339,51.92548","4.5464,51.91478","4.54591,51.91479"]
}

Now make the actual curl request. Values you need to fill in yourself are located within the brackets.

curl https://api.geojunxion.com/tdmv1/order 
  -d @{path_to_json_file}
  -H 'x-api-key: {token}' 
  -H 'content-type: application/json'

The result will be:

{
  "uuid": "318e774a_f0c0_11e9_82e4_02e9457d8866"
}

Save the result as a json file, containing the uuid json output. Next supply the file location as a parameter in the following curl request.

Request the Batch Job Result

curl https://api.geojunxion.com/tdmv1/fetch 
  -d @{uuid.json} 
  -H "x-api-key: {token}" 
  -H "Content-Type: application/json" 

The result will be:

{
  "destination_addresses": [
    "4.54260,51.91241",
    "4.53339,51.92548",
    "4.5464,51.91478",
    "4.54591,51.91479"
  ],
  "distance": [
    [
      null,
      2869,
      540,
      574
    ]
  ],
  "duration": [
    [
      null,
      155,
      49,
      51
    ]
  ],
  "origin_addresses": [
    "4.54270,51.91240"
  ],
  "status": "Finished"
}

SDKS

It is also possible to access the Time Distance Matrix API using our supplied SDKS for Android and iOS. Each zip file contains a readme with details how to use the resource.