私はIMPORTXML関数の必要性を排除することでこれにアプローチします。
あなたは既にGoogle Appsスクリプトに書いている言及し、その次のステップは、IMPORTXML機能がやっているんスクリプトを実装することです - 2点間の距離を計算します。
を使用して、選択した機能を実行し、パラメータ(例: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関数は実際にはこのシートの元のソリューションと同じように、スクリプトの代わりに使用されていました。それは* far *信頼性が低いので、私はIMPORTXMLオプションとそのはるかに高い信頼性を発見したときに私は興奮しました。いずれにせよ、Googleマップへの呼び出しは時々タイムアウトしているように見えますが、私はそれらをクリアするために(私とは対照的に)ユーザのために自動的に、または簡単に(1つのメニューオプション)を探しています!私は他の方法で進歩を遂げていますが、私の他の質問に対するあなたの返答の一部に感謝します。ありがとう! – Alex