我会通过消除对IMPORTXML功能的需求来解决这个问题。
您提到您已经在使用Google Apps脚本编写脚本,因此下一步是实施一个脚本来完成IMPORTXML功能的功能 - 计算2个点之间的距离。
您可以使用onFormSubmit
trigger执行选择的功能,并通过传递参数(即function runsWhenFormSubmits(event)
)并因此使您的功能能够访问表单提交object。你可以使用built-in Maps API。您链接的电子邮件线程具有实际distance code already:
function getDirections(start, finish) {
// Start & finish are viable text addresses
var df = Maps.newDirectionFinder();
df.setOrigin(start).setDestination(finish);
return df.getDirections();
}
的对象布局显示here (in JSON format).
总结:
function runsWithForm(e) {
var origin = "123 Fake Street, Springfield, IL",
dest = "321 Real Street, Springfield, MO";
// When called via the Script Editor, the event object is not present.
if(e) {
var formItems = e.response.getItemResponses();
var startAddressIndex = 0; // If the starting address is the first answer.
var destinationAddressIndex = 1; // If the destination address is the 2nd answer.
// Assuming the response is a simple String (vs. String[], etc).
origin = formItems[startAddressIndex].getResponse();
dest = formItems[destinationAddressIndex].getResponse();
}
var directions = getDirections(origin, dest);
if(directions.routes.length == 0)
throw new Error("No routes found between '" + origin + "' and '" + dest + "'.");
// Add code to do stuff with the existing route.
}
虽然这是一个可能的选项,以克服我的烦恼......的IMPORTXML函数实际上是这个脚本的替代品,就像这张表格中的原始解决方案。它远远不可靠,所以当我发现IMPORTXML选件及其更高的可靠性时,我感到非常兴奋。无论哪种方式,对Google地图的呼叫有时似乎只是超时(或某些),我正在寻找一种方法来自动或简单地(一个菜单选项)为用户(而不是我)来清除它们!我以其他方式取得进展,部分要归功于你对我另一个问题的回复。谢谢! – Alex