Skip to content

Instantly share code, notes, and snippets.

@baxeico
Created February 9, 2015 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baxeico/c400e3e6b3cd05f7d9d4 to your computer and use it in GitHub Desktop.
Save baxeico/c400e3e6b3cd05f7d9d4 to your computer and use it in GitHub Desktop.
Google App Script to geocode a list of addresses in a Spreadsheet
function myFunction() {
var sheet = SpreadsheetApp.getActiveSheet();
var range = sheet.getDataRange();
var cells = range.getValues();
var latitudes = [];
var longitudes = [];
for (var i = 0; i < cells.length; i++) {
var address = cells[i][0];
var geocoder = Maps.newGeocoder().geocode(address);
var res = geocoder.results[0];
latitudes.push([res.geometry.location.lat]);
longitudes.push([res.geometry.location.lng]);
}
sheet.getRange('B1').offset(0, 0, latitudes.length).setValues(latitudes)
sheet.getRange('C1').offset(0, 0, latitudes.length).setValues(longitudes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment