【发布时间】:2016-04-04 19:03:10
【问题描述】:
我有一个函数计算两个坐标之间的距离,如下所示:
function distance(origin, destination) {
//Utilities.sleep(Math.random() * 60000);
destination = destination + "";
if (destination.split(",").length == 2) {
var directions = Maps.newDirectionFinder()
.setOrigin(origin)
.setDestination(destination)
.getDirections();
if (directions.routes.length > 0) {
return directions.routes[0].legs[0].distance.value / 1000;
}
return "-";
}
return 0;
}
在电子表格中使用如下:
=distance("83.342353,23.23353", V2)
该函数运行良好,但由于我的电子表格有 200 多行,因此达到了 url 调用的速率限制。错误信息是:
服务在短时间内调用太多次:urlfetch protected host rateMax。在通话之间尝试 Utilities.sleep(1000)。 (第 5 行)
建议的修复方法是在代码中添加Utitlies.sleep()。我应该把这个放在哪里?
【问题讨论】:
-
您是否将其用作 Google 表格中的自定义函数?
-
是的。我已将公式添加到问题中。
标签: google-apps-script google-sheets