Last active
March 9, 2023 18:13
-
-
Save bpwebs/d36d095a69cb66e818aff0a61f21f44e to your computer and use it in GitHub Desktop.
Generate Static Google Maps in Google Sheets - Add place markers
This file contains 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
Generate Static Google Maps in Google Sheets - Add place markers |
This file contains 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
/** | |
* Create Static Google Maps with place markers from Google Sheets data | |
* bpwebs.com | |
*/ | |
function createStaticGoogleMap(){ | |
const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data"); | |
const range = ss.getActiveRange(); | |
const data = range.getValues(); | |
if(data==""){throw new Error("please select a valid range");} | |
let map = Maps.newStaticMap(); | |
map.setSize(600,400); | |
map.setMarkerStyle(Maps.StaticMap.MarkerSize.MID, Maps.StaticMap.Color.RED, "A"); | |
for(let i = 0;i<data.length;i++){ | |
var latlong = data[i][0]; | |
map.addMarker(latlong); | |
} | |
ss.insertImage(map.getBlob(),5,3); | |
} | |
/**CREATE CUSTOM MENU TO RUN THE SCRIPT */ | |
function onOpen(){ | |
SpreadsheetApp.getUi().createMenu('My Menu') | |
.addItem('Create Static Map','createStaticGoogleMap') | |
.addToUi(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment