Tutorial: making a distance matrix & calculating times to multiple locations

by Niharika Sisodia
on Jul 19, 2018 4:29:45 PM

A matrix is made up of rows and columns. In the example below the matrix shows commute times for 3 staff members to 3 different office locations. Each cell that calculates the journey time in the matrix below can also be defined as an element.

This means that an office manager can analyse the commute times of every employee to every possible office and come to the best decision.

distance-matrix

To do this chart we will use the TravelTime Search API. The API is free to use for up to 10,000 searches per month. This will be enough to populate a matrix of 10,000 x 2,000 using the standard Time Filter. To do this on the free plan may require you to spread out results as it’s possible to search up to 30 times per minute.

GET AN API KEY


How to use this guide

STEP 1: Learn the basics
STEP 2: Select from two options
  1. One origin to many destinations search
    Learn how to do a simple 1 origin > multiple destinations search 
    For example, calculate the travel times for 1 person to depart their home location at 5 pm to 100 possible local nearby restaurants
  2. Many destinations to one origin search
    Learn how to do a simple 1 destination > multiple origins search
    For example, calculate the travel time for 100 employee home addresses to arrive at 1 office destination at 9 am
STEP 3: Format to a matrix

STEP 1: Learn the basics 

The basics

The TravelTime Search API is used in this tutorial, get a free API key here.

The request that we will be explaining is called Time Filter. The documentation for the Time Filter endpoint can be found here. Time Filter is used if you want to find the journey time from a single origin to 1000s of destinations (or vice versa).

You can use Time Filter to filter points of interest within a certain travel time. You can also integrate the filter function into any app using an API. Below are some examples for each of the three search types.

To use Time Filter you will need to create a simple JSON request. You can learn how to create a JSON request in our documentation. For the examples below, the following parameters are first entered by the user:

  • Departure or arrival location
  • Mode of transport
  • Travel time limit
  • Time of the day

STEP 2: Select from two options

One-to-many search introduction

The example below shows how Zoopla use Time Filter to allow their users to search from their starting address to multiple potential houses - a one-to-many search.  

On a property search a user enters:

  • A single destination - for example, where they work
  • Their transport preferences - their preferred mode of transport and maximum time they’re willing to commute

This search area is then cross-referenced to all of the points of interest in the Zoopla database (the houses for sale) and a travel time to each relevant property is listed.

Houses that are reachable within the travel time limit are shown. The houses are displayed both as pins on the map and in a list view.

distance-matrix

 

distance-matrix

How do I code a one-to-many search?

To explain how Zoopla filtered all the points we have created a departure search example request. Here we enter locations IDs as a set of coordinates for London Center, Hyde Park and ZSL London Zoo.

You’ll notice that the request below assumes that you know the coordinates for these locations. If you don’t have these, you will need to use a geocoder. The TravelTime Search API has a free geocoder or you can choose another supplier.

Departure point: London Center

Mode of transport: Bus

Maximum travel time area: 30 minutes - but the API only accepts this in seconds so we multiplied 30 by 60 seconds to get the travel time of 1800 below

Time of day, date: 8 am, 9th July 2018

Range option is enabled and will return up to 3 travel times within a range of 600 seconds in ascending order

Every request requires an API key and ID for authentication. Get keys here.

How do I understand the one-to-many search code response?

The response below lists travel times from the origin to multiple destinations in seconds. For example, it takes 1723 seconds (or just under 29 minutes) to depart London centre and reach Hyde Park.

You will also notice there are 3 possible travel times from the centre to the park. This is because the ‘range’ feature is enabled. This calculates results assuming the user can select different routes for the journey.

Finally, you can see that ZSL London Zoo is not reachable. This means that it is not possible to reach the zoo within the 30-minute limit if you increase the maximum travel time area this will probably be possible.

If you adjust the request you can also get these things returned:

  • Distance if driving, walking or cycling
  • Distance break down if driving, walking or cycling
  • Fare data if using public transport and searching in the UK
  • Route break down for all modes

Many-to-one search introduction

The example below shows how Jobsite use Time Filter to calculate travel times for multiple job applicants to arrive at a single job location. Multiple candidates have applied for one job. The client has specified that they would only consider applicants that live within a certain travel time. Jobsite staff can filter candidates by maximum travel time to the job using a many-to-one search.

The candidates that are not within the specified travel time will be excluded. Candidates that can reach the job within the limit are shown. To find the ideal candidate, the results can be further filtered by a number of criteria, including:

  • Commute time
  • Cost of commute
  • Mode of transport used to commute
distance-matrixHow do I code a many-to-one search?

To explain how Jobsite filtered all the points we have created a departure search example request. We have selected an arrival search so the user can arrive at the job location (in this example London centre) from the multiple destinations (Hyde Park, ZSL London Zoo)

You’ll notice that the request below assumes that you know the coordinates for these locations. If you don’t have these, you will need to use a geocoder. The TravelTime Search API has a free geocoder or you can choose another supplier.

Arrival point: London Center

Mode of transport: Public transport

Maximum travel time area: 1900 seconds (just over 31 minutes) - but the API only accepts this in seconds so we multiplied minutes by 60 seconds to get the travel time of 1900 below

Time of day, date: 8 am, 9th July 2018

Every request requires an API key and ID for authentication. Get keys here.

How do I understand the many-to-one search code response?

The response below lists travel times from multiple origins to the single destination in seconds. For example, it takes 1723 seconds (or just under 29 minutes) to arrive at London centre when departing from Hyde Park.

You can see that ZSL London Zoo is not reachable. This means that it is not possible to reach the zoo within the travel time limit if you increase the maximum travel time area this will probably be possible.

If you adjust the request you can also get these things returned:

  • Distance if driving, walking or cycling
  • Distance break down if driving, walking or cycling
  • Fare data if using public transport and searching in the UK
  • Route break down for all modes

 

STEP 3: Apply step 2 format to a matrix 

Distance matrix search introduction

Now we can return to the distance matrix. The example below (as mentioned at the start of the article) shows the distance between pairs of origins and destinations. The example below shows how a distance matrix can be used to analyse staff travel times when deciding on an office relocation.

distance-matrix

The distance matrix shows commute times for all staff to each office address by different modes of transport. This data can be analysed to assess the effect of the office move on staff.There are multiple members of staff and multiple potential new office locations. The HR manager needs to know all possible commute times from all employee addresses to all office addresses. The user can create a distance matrix for this information.

How do I code a distance matrix?

Other distance matrix APIs, such as Google’s, calculate a matrix using origin-destination pairs. This means they count a ‘search’ for calculating the journey time from a single origin to a single destination. This article compares the two APIs side by side.

Using the TravelTime Search API you can do this using multiple Time Filter requests. This means either:

  • From one origin to thousands of destinations in one ‘search’. For example, if I depart from the origin at 8 am how long would it take to reach each of my 200 destination points of interest?
  • It can also be from thousands of destinations to a single origin in one ‘search’. For example, if I need to arrive at my origin at 8 am how long would I need to travel from each of my 200 destination points of interest?

The type of search you do depends on which option you picked in the first part of this tutorial. To make a travel time matrix you need to create a request with multiple arrivals or departure search.

distance-matrix

GET AN API KEY

Column 1 on the table above shows the multiple departure locations. The first row of locations shows proposed office locations, these are the arrival locations. The analysis is done assuming that the employees need to reach the office locations by 8 am.

To complete this we will do multiple arrival searches

The table from the above has departure locations on the left-hand side column and the first row represents destinations. In order to get travel time results, we would need to create a request that has multiple arrival searches.

For this, we will have 3 departure locations in a single request. One to get travel times to E5 0AA, second to EC4P 4BF and third from EC4M 9EB. We will disable range to get a single travel time result for each search.

Here’s an example:

Here we get results for all 3 journeys that could be placed into a table to create a travel time matrix. Here locations could be changed with employees addresses to perform office relocation analysis or create any other distance matrix.

The response has travel times. When we display these results on a table we get a travel time matrix. (Times in seconds)

distance-matrix

 

Which countries does the TravelTime Search API support? 

Australia  Germany Norway
Austria Hungary Poland
Belgium Ireland Portugal
Canada Israel Spain
Czech Republic Itlay Sweden
Denmark Latvia Switzerland
Estonia Lithuania United Kingdom
Finland Luxembourg United States
France Netherlands  

GET AN API KEY

Sign up for an API key now and start using The TravelTime Search API within 24 hours. To learn more about the Travel Time Search API and creating a distance matrix, visit our Time Filter page. Look at our office relocations page for more information on moving offices

 

Related

Which tech to choose: Analysis for office relocation

A supplier list to support your analysis for office relocation. Find tools to help you manage your office move. Get support with planning, location analysis, budgeting and staff management.

Niharika Sisodia Nov 6, 2018 12:21:16 PM
READ

3 ways to use business location analysis

Use business location analysis tools to support business decision making. Visualize staff commute times and create a travel time matrix for office relocation.

Niharika Sisodia Oct 17, 2018 11:50:01 AM
READ

Making a commute time visualization map

Make a commute time visualisation. View potential areas to work on a commute distance map. Search by travel time instead of distance.

Niharika Sisodia Sep 11, 2018 10:24:06 AM
READ

Using data visualization & location analysis to identify where to locate a new hospital

A location analysis and data visualization case study assessing where to place a new hospital. The case study maps drive times and public transport data to see which area is the easiest to access.

Niharika Sisodia Sep 5, 2018 3:10:30 PM
READ

How to make an office location map

How to make an office location map. Analyse potential areas for your office. Visualise office locations on a map. Plot staff addresses and analyse commute times.Choose the ideal location for your office.

Niharika Sisodia Sep 4, 2018 3:38:20 PM
READ

What is QGIS?

Use QGIS to view, edt and analyse geospatial data. QGIS is a free alternative to commercial GIS software.

Niharika Sisodia Aug 8, 2018 11:06:26 AM
READ