Luke, thanks for your reply. That's exactly what I've been trying to do with the code below, a script that I tried to run in the spreadsheet that geocoded the address using the api and returned the coordinates to a new cell in the spreadsheet. After loading the page a couple times the script stopped working though, saying that the status of the geocoding was undefined. I thought the geocoder might have hit a frequency limit because it the spreadsheet ran the script everytime the map read it? Not sure if that's the problem though...
// GEOCODER
// Example use =ARRAYFORMULA(getLatLongRange(D2:G202)) where column D has street addresses,
// E has Cities, F3 has States and G3 has zip codes
//or =ARRAYFORMULA(getLatLongRange(D2:D202)) where column D has complete addresses
// Put this formula in second cell of the column where you want Latitude, Longitude pairs added.
// This works to get a series Latitude, Longitude pairs from a range of cells
function getLatLongRange(range) {
var n = range.length;
var m = range[0].length;
var LLArray =new Array(n);// We want record for each row passed to us
for (i=0; i<n; i++){
var fullAddress ="";
for (var j = 0; j < m; j++) {
fullAddress = fullAddress + " " + range[i][j];
}
try{
var latLong = "";
var gc = Maps.newGeocoder();
var geoJSON = gc.geocode(fullAddress);
Logger.log("fullAddress is " + fullAddress );
var lat = geoJSON.results[0].geometry.location.lat;
var lng = geoJSON.results[0].geometry.location.lng;
latLong = lat + ", " + lng;
}catch (e){
Logger.log("Geocoding Failed: fullAddress is " + fullAddress + " Status is " + geoJSON.status );
}
LLArray[i] =new Array(1);// We want to fill in only the current column for each row
LLArray[i][0] = latLong;
}
return LLArray; // return the answer to the cell which has the formula
}