Skip to content

Instantly share code, notes, and snippets.

Last active Apr 4, 2017
What would you like to do?
Google Sheets Geocoding Custom Function
// returns latlng from Google API
function GEOCODE(input){
var data = JSON.parse(queryGoogle(input));
var location = data.results[0].geometry.location;
return + ", " + location.lng;
function queryGoogle(address){
var options =
"method" : "GET",
"followRedirects" : true,
"muteHttpExceptions": true
// wouldn't it be great if we had a real getRequest method in Google Apps Script
// you'll have to get your own API key from
var queryString = "?address="+address+"&key="+"YOUR API KEY";
var request = UrlFetchApp.fetch(""+queryString, options)
return request.getContentText();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment