Skip to content

Instantly share code, notes, and snippets.

@baxeico baxeico/Code.gs
Created Feb 9, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.