In this post, I will show you how to Find distance between multiple location in google sheets using Google Apps Script and how to calculate the duration.
Internally, it uses the Google Maps service of Google Apps Script to find the distance and directions between the Multiple Location
In sheet where we add manually starting address, waypoints 1-5 and end address (Column A to H). distance and time is calculated using apps script and comes in column I and J
If we add the address in google maps It will look like this. You don’t need to add on the map, I just only show the demo. How it will look. I do all the things to understand them easily distance between multiple location in google sheets
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Custom Menu')
.addItem('Fetch Distance and Time', 'mainFun')
.addToUi();
}
function mainFun() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
var data = sheet.getRange(2, 1, sheet.getLastRow()-1, 8).getValues();
Logger.log(data.length);
for(var i=0; i
In sheet menu, tools > script editor. The script editor will open Paste the code below in script editor. After pasting the code please refresh the sheet.
You will see the custom menu, run that menu than authorize the code and after authorization distance and time are calculated.