【发布时间】:2019-09-16 11:13:09
【问题描述】:
我在 Google 电子表格中使用以下函数查找旅行时间以及两个位置或邮政编码之间的交通数据。
输入参数将来自位置、目的地、到达时间(这是在上午 6 点或上午 8 点之间)具有不同定义时间的相同脚本
根据我的谷歌脚本函数中的上述输入参数,它应该返回旅行时间,但我收到一个错误,服务在一天内调用了太多次:路线。 (第 40 行)。我正在使用下面的自定义函数,我的工作表中有 40 行。这就是函数。有什么办法可以使它成为一个数组公式?这有助于避免不必要的电话吗?
function GetDuration(location1, location2, mode) {
//var arrive = new Date(new Date().getTime() + (10 * 60 * 60 * 1000));//arrive in ten hours from now
// var arrive=new Date(2019, 09, 07, 06);// 7th of September 2019 06:00 am
var arrive = new Date();
arrive.setHours(6,0,0,0);
var directions = Maps.newDirectionFinder().setArrive(arrive)
.setOrigin(location1)
.setDestination(location2)
.setMode(Maps.DirectionFinder.Mode[mode])
.getDirections();
// Get a script lock, because we're about to modify a shared resource.
var lock = LockService.getScriptLock();
// Wait for up to 30 seconds for other processes to finish.
lock.waitLock(20000);
Utilities.sleep(1000);
return directions.routes[0].legs[0].duration.text;
【问题讨论】:
标签: javascript google-maps google-apps-script google-sheets-api