Created
May 29, 2023 17:33
-
-
Save bpwebs/260fe15094026a9ae4884d4b3a100973 to your computer and use it in GitHub Desktop.
How to Calculate the Distance Between Two Addresses in Google Sheets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function CALCULATE_DRIVING_DISTANCE(origin, destination) { | |
var directions = Maps.newDirectionFinder() | |
.setOrigin(origin) | |
.setDestination(destination) | |
.setMode(Maps.DirectionFinder.Mode.DRIVING) | |
.getDirections(); | |
var distance = directions.routes[0].legs[0].distance.value; | |
distance /= 1000; // Convert meters to kilometers | |
return Number (distance.toFixed(2)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment