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:
In Google Sheets, click Extensions then select Apps Script.
A new tab will load for Google Apps Script, showing the code area.
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:
Google Sheets Distance Between Two Addresses Custom Functions Script
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.
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:
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”)
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.
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.
In Google Sheets, click Extensions then select Apps Script.
A new tab will load for Google Apps Script, showing the code area.
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:
Google Sheets Distance Between Two Addresses Custom Functions Script
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.
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:
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”)
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.