The code below gets the distance between 2 different addresses and returns the distance in miles, kilometers or minutes. My understanding was that I could execute my app-script in a web app using google.script.run.googleMaps();
My question is how do I use input fields as my from and two columns to replicate the same result in a web app?
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 Math.floor(meters * 0.000621371);
break;
case "kilometers" :
return meters / 1000;
break;
case "minutes" :
var duration = getTheLeg["duration"]["value"];
return duration / 60;
break;
default :
return "Error: Wrong unit type";
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…