Skip to content

Instantly share code, notes, and snippets.

@JayGoldberg
Created September 16, 2022 21:00
Show Gist options
  • Save JayGoldberg/c2e0b0fecc40c15fab50a9aff4e7a258 to your computer and use it in GitHub Desktop.
Save JayGoldberg/c2e0b0fecc40c15fab50a9aff4e7a258 to your computer and use it in GitHub Desktop.
Apps Script use Google Maps Javascript API with custom-defined script property API key
// addresses "Exception: Service invoked too many times for one day: geocode" because the built-in Maps App does not support API keys
// you must create an API key in Maps API in the Google Cloud Console for insertion into Script Properties `mapsApiKey`
function doGeoCode(address) {
var serviceUrl = `https://maps.googleapis.com/maps/api/geocode/json?address=${address}&key=${ScriptProperties.getProperty('mapsApiKey')}`;
var response=UrlFetchApp.fetch(serviceUrl, options);
if(response.getResponseCode() == 200) {
var responseJSON = JSON.parse(response.getContentText());
if (responseJSON !== null) { return responseJSON; }
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment