I am currently producing a script that will compare a the time taken to travel between 90 addresses to each other. The result of the script should be a list that contains the time taken to travel to each address from each other.
I've run into a series of issues whilst trying to resolve this. The main issue is that resulting distance matrix will have around 8100 elements. Google script's max execution time is 30 minutes and thus the script keeps timing out.
Any ways that I can improve the script to make it run faster?
The aim of this script is to produce a list with StartID, EndID and Time. I would then be able to filter the list to find addresses within an hour of each other.
I've hit my daily quota of 3 hours execution time already so any help would be much appreciated. Thanks!
function maps(origin, destination) {
var driving = Maps.DirectionFinder.Mode.DRIVING
var transit = Maps.DirectionFinder.Mode.TRANSIT
var modeSet = driving
var directions = Maps.newDirectionFinder()
.setOrigin(origin)
.setDestination(destination)
.setMode(modeSet)
.setOptimizeWaypoints(true)
.getDirections()
var result = directions
return result;
}
function GoogleMaps() {
//get distance
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("ABC");
var outputSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("EFG");
var lastrow = sheet.getLastRow();
var lastcolumn = sheet.getLastColumn();
var range = sheet.getRange(2, 3, lastrow-1, 3);
//var range = sheet.getRange(2, 3, 3, 3);
//Origin is in row 2, column 3
var values = range.getValues();
var output = []
for (var i = 0; i < values.length; ++i)
{
var loop1 = values[i]
var start = values[i][1]
var startId = values[i][0]
for (var j = 0; j < values.length; j++) {
var loop2 = values[j]
var end = values[j][1]
var endId = values[j][0]
var result = maps(start, end)
var status = result.status
try{
var time = result.routes[0].legs[0].duration.value / 60;
var row = [startId, endId, time]
output.push(row)
} catch(err){
Logger.log(err);
}
}
}
var outputLength = output.length
var outputRange = outputSheet.getRange(1,1,outputLength,3);
outputRange.setValues(output);
}
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/b6ecb94b-ef6c-4ff3-a81e-9fe467759b77%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAHpDaihx2jxD_6UUDdsCHuwXHs3Q6bj2c8kjZUpEbHQoHcieAQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CADJ_Tyb1vL_hv9oQPrVZy5%3DjjhzntcYG0O-_wY3z40T36aua8A%40mail.gmail.com.
The aim of this script is to produce a list with StartID, EndID and Time. I would then be able to filter the list to find addresses within an hour of each other.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/b6ecb94b-ef6c-4ff3-a81e-9fe467759b77%40googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/CAHpDaihx2jxD_6UUDdsCHuwXHs3Q6bj2c8kjZUpEbHQoHcieAQ%40mail.gmail.com.
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-community+unsub...@googlegroups.com.