I am trying to set up a google sheet where I can pout in two addresses and get the distance and time travelled from google maps in the excel sheet
I have the script below – but it keeps coming up with an error – error is
Exception: Invalid argument: origin
GOOGLEMAPS @GOOGLEMAPS.gs:4
My script is below
your text
`function GOOGLEMAPS(start_address,end_address,return_type) {
var mapObj = Maps.newDirectionFinder();
mapObj.setOrigin(start_address);
mapObj.setDestination(end_address);
var directions = mapObj.getDirections();
var getTheLeg = directions["routes"][0]["legs"][0];
var meters = getTheLeg["distance"]["value"];
switch(return_type){
case "miles":
return meters * 0.000621371;
break;
case "minutes":
//get duration in seconds
var duration = getTheLeg["duration"]["value"];
//convert to minutes and return
return duration / 60;
break;
case "kilometers":
return meters / 1000;
break;
default:
return "error:wrong unit type";
}
}`
New contributor
Angela M is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.