我會通過消除對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