google apps script - Calculate driving distance in KM when a Form is submitted -


i need adapt script below when form submitted, response email indicates driving distance between origin (partida) , destination (destino) in kilometers.

var doctemplate = "1fteemzee52j244xldbzne7qkhnizfeokyzk1xnge3cs"; var docname     = "autorizaÇÃo para retirada de veÍculo";  // create function function onformsubmit(e) {  //get variables   var email_address = "user@example.com";   var nome = e.values[2];   var carro = e.values[3];   var data = e.values[4];   var hora = e.values[6];   var destino = e.values[7];   var motivo = e.values[5];   var partida = e.values[8];  // copy , start temp document   var copyid = driveapp.getfilebyid(doctemplate)                 .makecopy(docname+' para '+nome)                 .getid();    var copydoc = documentapp.openbyid(copyid);    var copybody = copydoc.getactivesection();     copybody.replacetext('keynome', nome);    copybody.replacetext('keycarro', carro);    copybody.replacetext('keydata', data);    copybody.replacetext('keyhora', hora);    copybody.replacetext('keydestino', destino);    copybody.replacetext('keymotivo',motivo);  // need put here simple calculator distance in km variable partida , variable destino    // salve temp document    copydoc.saveandclose();  // convert in pdf temp document , send email     var pdf = driveapp.getfilebyid(copyid).getas("application/pdf");     var subject = "autorizaÇÃo de veÍculo";    var body    = "esta é autorização do(a) " + nome + "";    mailapp.sendemail(email_address, subject, body, {htmlbody: body, attachments: pdf});   // delete temp document    driveapp.getfilebyid(copyid).settrashed(true); } 

a function calculating driving distance presented in google apps script quickstart: macros, menus, , custom functions. adapted version accepts multiple waypoints shown in looking distance between multiple points in googlesheets script.

with either of functions included, can modify code this:

... copybody.replacetext('keydestino', destino); copybody.replacetext('keymotivo',motivo);  // calculate distance in km partida destino var distancia = drivingdistance(partida, destino) / 1000; copybody.replacetext('keydistancia',distancia);  // save temp document copydoc.saveandclose(); ... 

if wish format calculation, use utilities.formatstring().


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -