I’ve been trying to improve the spreadsheet that I have so that I can save some time.
Here’s the deal:
Spreadsheet
This is the formula: =IF(M20 = “”, , VALUE(GOOGLEMAPS_DISTANCE(M20, N20, “driving”)))
And this is the script:
const GOOGLEMAPS_DISTANCE = (origin, destination, mode) => {
const { routes: [data] = [] } = Maps.newDirectionFinder()
.setOrigin(origin)
.setDestination(destination)
.setMode(mode)
.getDirections();
if (!data) {
throw new Error('No route found!');
}
const { legs: [{ distance: { text: distance } } = {}] = [] } = data;
return distance.slice(0,-3);
};
This works just fine, it calculates miles from point A to point B and returns the value.
What I want to make work, is empty miles, that is a little bit complicated.
But, I don’t know how to get the last value (destination) based on the name in column A and then I would send it to the function to calculate miles.
This is the goal
Nick Romano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.