Calculate Driving Time with Google Sheets

Gregory Jul 09, 2026

Ever found yourself planning a road trip or a delivery route and wished you could easily calculate the driving time between multiple locations? Google Sheets, with its built-in functions and add-ons, can do just that, saving you time and effort. Let's explore how to calculate driving time in Google Sheets.

a screenshot of a spreadsheet with multiple columns and numbers on the screen
a screenshot of a spreadsheet with multiple columns and numbers on the screen

Before we dive in, ensure you have Google Sheets installed and that you're comfortable with basic functions and formulas. If not, don't worry, we'll guide you through the process step by step.

How to Create a Google Dashboard
How to Create a Google Dashboard

Using Google Maps Distance Matrix API

The Google Maps Distance Matrix API is a powerful tool that allows you to calculate the driving distance and time between multiple locations. To use it in Google Sheets, you'll need to set up an API key and use the API's URLfetch service.

The Ultimate Google Sheets Keyboard Shortcut Cheat Sheet for Beginners & Pros
The Ultimate Google Sheets Keyboard Shortcut Cheat Sheet for Beginners & Pros

Here's a step-by-step guide to using the API:

Setting up an API key

Creating a tracker in google sheets
Creating a tracker in google sheets

1. Go to the Google Cloud Console (console.cloud.google.com).

2. Create a new project or select an existing one.

3. Enable the Distance Matrix API for your project.

How to Add Travel Time in Google Calendar - Technology Hacks and Tech Tips for Moms
How to Add Travel Time in Google Calendar - Technology Hacks and Tech Tips for Moms

4. Go to "APIs & Services" > "Credentials" and create a new API key.

Using the API in Google Sheets

1. In your Google Sheet, click on "Extensions" > "Apps Script."

A NEW Google Drive Cheat Sheet
A NEW Google Drive Cheat Sheet

2. Delete any existing code in the script editor and paste the following:

function doGet() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  var data = sheet.getRange('A1:B2').getValues();
  var origins = data.map(row => row[0]);
  var destinations = data.map(row => row[1]);

  var url = 'https://maps.googleapis.com/maps/api/distancematrix/json?origins=' + origins.join('|') + '&destinations=' + destinations.join('|') + '&key=YOUR_API_KEY';
  var response = UrlFetchApp.fetch(url).getContentText();
  var json = JSON.parse(response);

  var results = json.rows.map(row => row.elements.map(element => [element.duration.text]));
  sheet.getRange(1, 3, results.length, results[0].length).setValues(results);
}

3. Replace "YOUR_API_KEY" with your actual API key.

Attendance tracker templates for Google Sheets
Attendance tracker templates for Google Sheets
the 13 google sheets shortcuts list is shown in green and has white writing on it
the 13 google sheets shortcuts list is shown in green and has white writing on it
Free Google Sheets Weekly Schedule Template & Calendars
Free Google Sheets Weekly Schedule Template & Calendars
the front cover of technology tips and tricks for google dashboards, with an image of a
the front cover of technology tips and tricks for google dashboards, with an image of a
How to Auto Sort in Google Sheets
How to Auto Sort in Google Sheets
Habit Tracker Template - Track Your Habits with Google Sheets - FREE Template
Habit Tracker Template - Track Your Habits with Google Sheets - FREE Template
10 Google Sheets tricks you (probably) don’t know about
10 Google Sheets tricks you (probably) don’t know about
4 Google Scripts That Make Google Sheets More Powerful
4 Google Scripts That Make Google Sheets More Powerful
Keeping Track of EVERYTHING in Google Sheets
Keeping Track of EVERYTHING in Google Sheets
a laptop computer sitting on top of a wooden desk next to a potted plant
a laptop computer sitting on top of a wooden desk next to a potted plant
Effortless Mileage Tracker: Free Google Sheet for Accurate, Stress-Free Business Recordkeeping
Effortless Mileage Tracker: Free Google Sheet for Accurate, Stress-Free Business Recordkeeping
the ultimate guide to google's search engine info for every vehicle in the world
the ultimate guide to google's search engine info for every vehicle in the world
Google Sheets Checkbox Strikethrough
Google Sheets Checkbox Strikethrough
How to Use Google Sheets to Keep Every Part of Your Life Organized
How to Use Google Sheets to Keep Every Part of Your Life Organized
How to Use Slicers in Google Sheets
How to Use Slicers in Google Sheets
Master Google Sheets for Business
Master Google Sheets for Business
23 Best formulas for Google Sheets (+ Examples)
23 Best formulas for Google Sheets (+ Examples)
How To Create Checklists with Google Sheets
How To Create Checklists with Google Sheets

4. In your Google Sheet, enter the origins and destinations in columns A and B, respectively.

5. Run the function by clicking on the play icon in the toolbar, then select "doGet" and click "Run."

The driving time will be displayed in column C.

Using the GOOGLEFINANCE Function

While not as powerful as the Distance Matrix API, the GOOGLEFINANCE function can also provide driving time between two locations. It's simpler to use but has its limitations, such as not supporting multiple destinations.

Here's how to use it:

Basic usage

1. In your Google Sheet, enter the following formula in a cell:

``` =GOOGLEFINANCE("TIMEINLOCAL","location1","location2") ```

Replace "location1" and "location2" with the actual locations.

The driving time will be displayed in the cell.

Using the function with multiple locations

To calculate driving time between multiple locations, you can use a combination of INDEX, MATCH, and GOOGLEFINANCE functions. Here's how:

1. Create a table with locations in column A and the locations you want to calculate driving time to in column B.

2. In cell C2, enter the following formula:

``` =INDEX('GOOGLEFINANCE'!C:C,MATCH(A2,'GOOGLEFINANCE'!A:A,0)) ```

3. Drag this formula down to copy it for other locations.

The driving time will be displayed in column C.

And there you have it! You've now learned how to calculate driving time in Google Sheets using both the Google Maps Distance Matrix API and the GOOGLEFINANCE function. Happy planning!