Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bpwebs/d36d095a69cb66e818aff0a61f21f44e to your computer and use it in GitHub Desktop.
Save bpwebs/d36d095a69cb66e818aff0a61f21f44e to your computer and use it in GitHub Desktop.
Generate Static Google Maps in Google Sheets - Add place markers
Generate Static Google Maps in Google Sheets - Add place markers
/**
* 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