https://googleappsscriptrc.blogspot.com/2018/04/geocode-to-sheet.html
Last active
August 15, 2018 04:57
-
-
Save oshliaer/461359f5e6ac03b5cb7536ec36c93a4e to your computer and use it in GitHub Desktop.
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 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