Created
February 9, 2015 15:07
-
-
Save baxeico/c400e3e6b3cd05f7d9d4 to your computer and use it in GitHub Desktop.
Google App Script to geocode a list of addresses in a Spreadsheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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