I need to calculate the google maps derived distance between around 72,000 pairs of zip codes. I found a function online for google sheets which will do this, but I of course ran out of calls well before getting through the 72,000. So I set up billing within google maps api and now have an API key along with a ClientID. But I still can't get this to work. See below where "I tried adding this" based on what I've been able to find elsewhere.
function GOOGLEMAPS(start_address,end_address,return_type) {
// I tried adding this: var key = "";
// I tried adding this: var clientID = "YourClientIDHERE.apps.googleusercontent.com"
// I tried adding this: maps.setauthentication(clientID,key);
var mapObj = Maps.newDirectionFinder();
mapObj.setOrigin(start_address);
mapObj.setDestination(end_address);
Utilities.sleep(6000);
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 "hours":
// get duration in seconds
var duration = getTheLeg["duration"]["value"];
//convert to hours and return
return duration / 60 / 60;
break;
case "kilometers":
return meters / 1000;
break;
default:
return "Error: Wrong Unit Type";
}
}