May 8, 2024

## How to Calculate the Distance Between Two Addresses in Google Sheets

We have the following sheet with two addresses:

Let us find the distance between them, specifically the driving distance between them using a custom script. Here are the steps:

### 1. Click Extensions then Select Apps Script

In Google Sheets, click Extensions then select Apps Script.

A new tab will load for Google Apps Script, showing the code area.

### 2. Copy the Script and Paste it to Apps Script

We will copy the script for calculating distances between two addresses to the Apps Script. Click the link below first, then copy the script in it:

You can click this icon to copy the entire code:

Once done, go back to the Apps Script tab. Clear the code area then paste the code to it.

Click Save project.

### 3. Use =DRIVEDIST(origin,destination,unit) Function

The DRIVEDIST function finds the distance you need to drive from one location to another. The syntax is

=DRIVEDIST(origin, destination, unit)

Where

Origin and Destination are the addresses where you start and end your travel; and

Unit is the unit of distance you want to use.

The units you can use are the following:

• km for kilometers
• mi for miles
• nm for nautical miles
• m for meters
• ft for feet

Enclose them in double quotes.

For example, we want to find the distance between the two addresses, where the origin is in cell C1 and the destination is in cell C2. We want to find the distance in kilometers. The formula becomes:

=DRIVEDIST(C1, C2, “km”)

### 4. Press Enter

Press Enter to run the formula. The result is automatically calculated!

Just take note of the unit used in calculating the driving distance between the two addresses.

## How to Calculate the Geographical Distance Between Two Addresses in Google Sheets

Sometimes we want to find the distance between two points separated by bodies of water:

The DRIVEDIST function will not work because there is no continuous road connecting these two places. In fact, there is an ocean separating them! But how can we find the distance between them? Don’t worry, that’s what GEODIST is for! Here are the steps in using the GEODIST function. If you already followed the steps above, you can skip Steps 1 and 2 and go straight to Step 3.

### 1. Click Extensions then Select Apps Script

In Google Sheets, click Extensions then select Apps Script.

A new tab will load for Google Apps Script, showing the code area.

### 2. Copy the Script and Paste it to Apps Script

We will copy the script for calculating distances between two addresses to the Apps Script. Click the link below first, then copy the script in it:

You can click this icon to copy the entire code:

Once done, go back to the Apps Script tab. Clear the code area then paste the code to it.

Click Save project.

### 3. Use =GEODIST(origin,destination,unit) Function

The DRIVEDIST function finds the geographical distance between two addresses. The syntax is

=GEODIST(origin, destination, unit)

Where

Origin and Destination are the addresses where you start and end your travel; and

Unit is the unit of distance you want to use.

The units you can use are the following:

• km for kilometers
• mi for miles
• nm for nautical miles
• m for meters
• ft for feet

Enclose them in double quotes.

For example, we want to find the distance between the two addresses, where the origin is in cell C1 and the destination is in cell C2. We want to find the distance in kilometers. The formula becomes:

=GEODIST(C1, C2, “km”)

### 4. Press Enter

Press Enter to run the formula. The result is automatically calculated!

Just take note of the unit used in calculating the geographical distance between the two addresses.

Get Google Sheets productivity and automation tips delivered straight to your inbox