Created
September 16, 2022 21:00
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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