I'm trying to use the functions in Google Sheets to create separate Docs that includes a table outlining information from the current Sheets row followed by a Google Maps image of the location, which are saved under the filename "street"-"county" in Drive.
Everything works but the Static Maps. While the files save as the correct name, and the table information is correct per row, the map image used in every document is the same as the initial doc. Any suggestions would be greatly appreciated.
function makeDocument(){
var ss = SpreadsheetApp.getActiveSpreadsheet()
var sheet = ss.getActiveSheet()
var info = []
for (i=2; i <= 4; i++) { //sheet.getLastRow()
values = sheet.getRange(i, 1, 1, 11).getValues();
info[i] = {};
info[i]['id'] = values[0][0];
info[i]['sd'] = values[0][1];
info[i]['address'] = values[0][2];
info[i]['city'] = values[0][3];
info[i]['county'] = values[0][4];
info[i]['state'] = values[0][5];
info[i]['zip'] = values[0][6];
info[i]['puse'] = values[0][7];
info[i]['lat'] = values[0][8];
info[i]['lon'] = values[0][9];
info[i]['sl'] = values[0][10];
create_document(info[i]);
info[i] = {};
Logger.log(info[i]);
}
}
function create_document(info){
// Create document as address for filename
var doc = DocumentApp.create(info['address']+"-"+info['county'])
var body = doc.getBody()
// create and insert table
var cells = [
['Yardi Id','PUSE','Address','City','County','State','Service Level'],
[info['id'], info['puse'], info['address'], info['city'], info['county'], info['state'], info['sl']]
];
body.insertTable(0, cells);
body.appendImage(get_map_image(info['lat'],info['lon']))
doc.saveAndClose();
}
function get_map_image(lat, lon){
var image = Maps.newStaticMap()
.setSize(600, 800)
.setCenter(lat, lon)
.addMarker(lat, lon)
.addVisible(lat, lon)
.setZoom(21)
.setMapType(Maps.StaticMap.Type.SATELLITE)
.setFormat(Maps.StaticMap.Format.PNG32);
return(image);
}
The code is ugly but works. GPS in spreadsheet needs to be in decimal format.