Google maps 将OnEdit添加到脚本或在计算Google工作表中的单元格后停止运行脚本?服务调用次数过多,请尝试实用程序。睡眠(1000)
如何将OneEdit添加到脚本或防止脚本在特定的Google Sheets单元格中运行多次?我正在使用谷歌地图计算两点之间的时间,但调用服务的次数太多,请尝试实用程序。sleep(1000) 我正在使用的脚本:Google maps 将OnEdit添加到脚本或在计算Google工作表中的单元格后停止运行脚本?服务调用次数过多,请尝试实用程序。睡眠(1000),google-maps,google-apps-script,google-sheets,triggers,spreadsheet,Google Maps,Google Apps Script,Google Sheets,Triggers,Spreadsheet,如何将OneEdit添加到脚本或防止脚本在特定的Google Sheets单元格中运行多次?我正在使用谷歌地图计算两点之间的时间,但调用服务的次数太多,请尝试实用程序。sleep(1000) 我正在使用的脚本: /** * Get Distance between 2 different addresses. * @param start_address Address as string Ex. "300 N LaSalles St, Chicago, IL" * @param end_ad
/**
* Get Distance between 2 different addresses.
* @param start_address Address as string Ex. "300 N LaSalles St, Chicago, IL"
* @param end_address Address as string Ex. "900 N LaSalles St, Chicago, IL"
* @param return_type Return type as string Ex. "miles" or "kilometers" or "minutes" or "hours"
* @customfunction
*/
function GOOGLEMAPS(start_address,end_address,return_type) {
// https://www.chicagocomputerclasses.com/
// Nov 2017
// improvements needed
var mapObj = Maps.newDirectionFinder();
mapObj.setOrigin(start_address);
mapObj.setDestination(end_address);
var directions = mapObj.getDirections();
var getTheLeg = directions["routes"][0]["legs"][0];
var meters = getTheLeg["distance"]["value"];
switch(return_type){
case "miles":
return meters * 0.000621371;
break;
case "minutes":
// get duration in seconds
var duration = getTheLeg["duration"]["value"];
//convert to minutes and return
return duration / 60;
break;
case "hours":
// get duration in seconds
var duration = getTheLeg["duration"]["value"];
//convert to hours and return
return duration / 60 / 60;
break;
case "kilometers":
return meters / 1000;
break;
default:
return "Error: Wrong Unit Type";
}
}
我希望脚本在计算值后停止在特定电子表格单元格上运行。
有什么想法吗?
谢谢 使用
SpreadsheetApp.getActive().getSheetByName(“名称”).getRange(“选择范围”).activate()怎么样代码>在脚本末尾。或者这是添加脚本的正确方法吗?我在最后两个括号之间添加了代码,并保留了“名称”和“选择范围”文本的原样:
/**
* Get Distance between 2 different addresses.
* @param start_address Address as string Ex. "300 N LaSalles St, Chicago, IL"
* @param end_address Address as string Ex. "900 N LaSalles St, Chicago, IL"
* @param return_type Return type as string Ex. "miles" or "kilometers" or "minutes" or "hours"
* @customfunction
*/
function GOOGLEMAPS(start_address,end_address,return_type) {
// https://www.chicagocomputerclasses.com/
// Nov 2017
// improvements needed
var mapObj = Maps.newDirectionFinder();
mapObj.setOrigin(start_address);
mapObj.setDestination(end_address);
var directions = mapObj.getDirections();
var getTheLeg = directions["routes"][0]["legs"][0];
var meters = getTheLeg["distance"]["value"];
switch(return_type){
case "miles":
return meters * 0.000621371;
break;
case "minutes":
// get duration in seconds
var duration = getTheLeg["duration"]["value"];
//convert to minutes and return
return duration / 60;
break;
case "hours":
// get duration in seconds
var duration = getTheLeg["duration"]["value"];
//convert to hours and return
return duration / 60 / 60;
break;
case "kilometers":
return meters / 1000;
break;
default:
return "Error: Wrong Unit Type";
}
SpreadsheetApp.getActive().getSheetByName("Name").getRange("Select Range").activate();
}
谢谢你,我添加到我的脚本中,所以它看起来像下面这样。是您建议的正确方式,还是我需要将我的工作表和范围的实际名称添加到您的附加代码中,如:SpreadsheetApp.getActive().getSheetByName(Sheet1.getRange(B:B.activate();是,您需要添加工作表的名称和要结束的单元格范围。