Skip to content

Instantly share code, notes, and snippets.

@oshliaer
Last active August 15, 2018 04:57
Show Gist options
  • Save oshliaer/461359f5e6ac03b5cb7536ec36c93a4e to your computer and use it in GitHub Desktop.
Save oshliaer/461359f5e6ac03b5cb7536ec36c93a4e to your computer and use it in GitHub Desktop.
function geocode_Addresses() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var locationInfo = sheet.getRange("A:A").getValues();
var result = [];
for (var i = 0; i < locationInfo.length; i++) {
var row = [];
if(locationInfo[i][0].toString().length > 6){
var geoResults = Maps.newGeocoder().geocode(locationInfo[i][0]);
Utilities.sleep(1000);
if(geoResults.status == "OK"){
var lat = geoResults.results[0].geometry.location.lat;
var lng = geoResults.results[0].geometry.location.lng;
row.push(Utilities.formatString(
"=HYPERLINK(\"https://www.google.com/maps/?q=%s,%s\";\"%s, %s\")",
lat,
lng,
lat,
lng));
}else {
row.push("Не найдено совпадений");
}
} else {
row.push("");
}
result.push(row);
}
sheet.getRange("B:B").setValues(result);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment