Member-only story

Create a distance matrix in Python with the Google Maps API

Use the google maps API to obtain distances and duration between locations

Edward Jones
2 min readAug 6, 2020
Figure 1: Example of a distance matrix (in km)

What you will learn in this article

  • How to calculate the actual duration and distance according to google maps
  • How to export your results in a clean excel
  • How to iterate over each possible combination

Give a clap if you liked this article.

example output

Step 0: Environment preparation

Install the googlemaps package & import pandas & itertools.

Step 1: Load the data

For learning purposes, I have created a dummy dataset. You can download the dataset here.

--

--

Responses (3)