Skip to content

Instantly share code, notes, and snippets.

@chipoglesby
Created August 4, 2015 19:16
Show Gist options
  • Select an option

  • Save chipoglesby/9d136ad01b204ece8e09 to your computer and use it in GitHub Desktop.

Select an option

Save chipoglesby/9d136ad01b204ece8e09 to your computer and use it in GitHub Desktop.
Geocode postal addresses
function geocode_Addresses() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var locationInfo = sheet.getRange(1, 1, sheet.getLastRow() - 1, 1).getValues();
var geoResults, lat, lng;
for (var i = 0; i < locationInfo.length; i++) {
geoResults = Maps.newGeocoder().geocode(locationInfo[i]);
// Get the latitude and longitude
lat = geoResults.results[0].geometry.location.lat;
lng = geoResults.results[0].geometry.location.lng;
sheet.getRange(i+1, 2, 1, 1).setValue(lat + "," + lng);
Utilities.sleep(1000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment