地点間のルートを取得できます。
次の例は、このクラスを使用してタイムズ スクエアからセントラル パークまでのルートを取得し、最初にリンカーン センターに立ち寄って、地図上に場所と経路をプロットし、地図をメールで送信する方法を示しています。
// Get the directions. const directions = Maps.newDirectionFinder() .setOrigin('Times Square, New York, NY') .addWaypoint('Lincoln Center, New York, NY') .setDestination('Central Park, New York, NY') .setMode(Maps.DirectionFinder.Mode.DRIVING) .getDirections(); const route = directions.routes[0]; // Set up marker styles. let markerLetterCode = 'A'.charCodeAt(); // Add markers to the map. const map = Maps.newStaticMap(); for (let i = 0; i < route.legs.length; i++) { const leg = route.legs[i]; if (i === 0) { // Add a marker for the start location of the first leg only. map.setMarkerStyle( Maps.StaticMap.MarkerSize.MID, Maps.StaticMap.Color.GREEN, String.fromCharCode(markerLetterCode), ); map.addMarker(leg.start_location.lat, leg.start_location.lng); markerLetterCode++; } map.setMarkerStyle( Maps.StaticMap.MarkerSize.MID, Maps.StaticMap.Color.GREEN, String.fromCharCode(markerLetterCode), ); map.addMarker(leg.end_location.lat, leg.end_location.lng); markerLetterCode++; } // Add a path for the entire route. map.addPath(route.overview_polyline.points); // Send the map in an email. const toAddress = Session.getActiveUser().getEmail(); MailApp.sendEmail( toAddress, 'Directions', `Please open: ${map.getMapUrl()}&key=YOUR_API_KEY`, { htmlBody: 'See below.<br/><img src="cid:mapImage">', inlineImages: { mapImage: Utilities.newBlob(map.getMapImage(), 'image/png'), }, }, );
関連情報
メソッド
詳細なドキュメント
add Waypoint(latitude, longitude)
ポイント(緯度/経度)を使用して、ルートが通過する必要がある経由地を追加します。
// Creates a DirectionFinder with a wapoint at Lincoln Center. const directionFinder = Maps.newDirectionFinder().addWaypoint( 40.772628, -73.984243, );
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
latitude | Number | 経由地の緯度。 |
longitude | Number | 経由地の経度。 |
戻る
Direction - 呼び出しの連結を容易にする DirectionFinder オブジェクト。
add Waypoint(address)
住所を使用して、ルートが通過する必要がある経由地を追加します。
// Creates a DirectionFinder with a wapoint at Lincoln Center. const directionFinder = Maps.newDirectionFinder().addWaypoint( 'Lincoln Center, New York, NY', );
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
address | String | 住所。 |
戻る
Direction - 呼び出しの連結を容易にする DirectionFinder オブジェクト。
clear Waypoints()
現在の経由地セットをクリアします。
const directionFinder = Maps.newDirectionFinder(); // ... // Do something interesting here ... // ... // Remove all waypoints added with addWaypoint(). directionFinder.clearWaypoints();
戻る
Direction - 呼び出しの連結を容易にする DirectionFinder オブジェクト。
get Directions()
設定された出発地、目的地、その他のオプションを使用してルートを取得します。
// Logs how long it takes to walk from Times Square to Central Park. const directions = Maps.newDirectionFinder() .setOrigin('Times Square, New York, NY') .setDestination('Central Park, New York, NY') .setMode(Maps.DirectionFinder.Mode.WALKING) .getDirections(); Logger.log(directions.routes[0].legs[0].duration.text);
戻る
Object - こちらで説明されているように、ルートのセットを含む JSON オブジェクト。
関連情報
set Alternatives(useAlternatives)
ランク付けが最も高いルートのみではなく、代替ルートを返すかどうかを設定します(デフォルトは false)。true の場合、結果オブジェクトの routes 配列に複数のエントリが含まれることがあります。
// Creates a DirectionFinder with alternative routes enabled. const directionFinder = Maps.newDirectionFinder().setAlternatives(true);
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
use | Boolean | 代替ルートを返す場合は true、それ以外の場合は false。 |
戻る
Direction - 呼び出しの連結を容易にする DirectionFinder オブジェクト。
set Arrive(time)
到着予定時刻を設定します(該当する場合)。
// Creates a DirectionFinder with an arrival time of 2 hours from now. const now = new Date(); const arrive = new Date(now.getTime() + 2 * 60 * 60 * 1000); const directionFinder = Maps.newDirectionFinder().setArrive(arrive);
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
time | Date | 到着時刻。 |
戻る
Direction - 呼び出しの連結を容易にする DirectionFinder オブジェクト。
関連情報
set Avoid(avoid)
特定の種類の制限を回避するかどうかを設定します。
// Creates a DirectionFinder that avoid highways. const directionFinder = Maps.newDirectionFinder().setAvoid( Maps.DirectionFinder.Avoid.HIGHWAYS, );
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
avoid | String | Avoid の定数値。 |
戻る
Direction - 呼び出しの連結を容易にする DirectionFinder オブジェクト。
関連情報
set Depart(time)
ご希望の出発時刻を設定します(該当する場合)。
// Creates a DirectionFinder with a departure time of 1 hour from now. const now = new Date(); const depart = new Date(now.getTime() + 1 * 60 * 60 * 1000); const directionFinder = Maps.newDirectionFinder().setDepart(depart);
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
time | Date | 出発時刻。 |
戻る
Direction - 呼び出しのチェーンを容易にする DirectionFinder オブジェクト。
関連情報
set Destination(latitude, longitude)
ポイント(緯度/経度)を使用して、ルートを計算する終了地点を設定します。
// Creates a DirectionFinder with the destination set to Central Park. const directionFinder = Maps.newDirectionFinder().setDestination( 40.777052, -73.975464, );
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
latitude | Number | 終了地点の緯度。 |
longitude | Number | 終了地点の経度。 |
戻る
Direction - 呼び出しのチェーンを容易にする DirectionFinder オブジェクト。
set Destination(address)
住所を使用して、経路を計算する終了地点を設定します。
// Creates a DirectionFinder with the destination set to Central Park. const directionFinder = Maps.newDirectionFinder().setDestination( 'Central Park, New York, NY', );
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
address | String | 終了アドレス。 |
戻る
Direction - 呼び出しのチェーンを容易にする DirectionFinder オブジェクト。
set Language(language)
ルート案内で使用する言語を設定します。
// Creates a DirectionFinder with the language set to French. const directionFinder = Maps.newDirectionFinder().setLanguage('fr');
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
language | String | BCP-47 言語識別子。 |
戻る
Direction - 呼び出しの連結を容易にする DirectionFinder オブジェクト。
関連情報
set Mode(mode)
移動手段を設定します(デフォルトは運転)。
// Creates a DirectionFinder with the mode set to walking. const directionFinder = Maps.newDirectionFinder().setMode( Maps.DirectionFinder.Mode.WALKING, );
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
mode | String | Mode の定数値。 |
戻る
Direction - 呼び出しの連結を容易にする DirectionFinder オブジェクト。
関連情報
set Optimize Waypoints(optimizeOrder)
地点をより効率的な順序に並べ替えて、指定されたルートを最適化するかどうかを設定します(デフォルトは false)。
// Creates a DirectionFinder with wapoint optimization enabled. const directionFinder = Maps.newDirectionFinder().setOptimizeWaypoints(true);
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
optimize | Boolean | 注文を最適化する場合は true、それ以外の場合は false。 |
戻る
Direction - 呼び出しの連結を容易にする DirectionFinder オブジェクト。
関連情報
set Origin(latitude, longitude)
ポイント(緯度/経度)を使用して、ルートを計算する出発地を設定します。
// Creates a DirectionFinder with the origin set to Times Square. const directionFinder = Maps.newDirectionFinder().setOrigin( 40.759011, -73.984472, );
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
latitude | Number | 出発地の緯度。 |
longitude | Number | 出発地の経度。 |
戻る
Direction - 呼び出しの連結を容易にする DirectionFinder オブジェクト。
set Origin(address)
住所を使用して、経路を計算する出発地を設定します。
// Creates a DirectionFinder with the origin set to Times Square. const directionFinder = Maps.newDirectionFinder().setOrigin( 'Times Square, New York, NY', );
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
address | String | 開始アドレス。 |
戻る
Direction - 呼び出しのチェーンを容易にする DirectionFinder インスタンス。
set Region(region)
位置情報の名前を解釈する際に使用する地域を設定します。サポートされている地域コードは、Google マップでサポートされている ccTLD に対応しています。たとえば、地域コード「uk」は「maps.google.co.uk」に対応します。
// Creates a DirectionFinder with the region set to France. const directionFinder = Maps.newDirectionFinder().setRegion('fr');
パラメータ
| 名前 | 型 | 説明 |
|---|---|---|
region | String | 使用する地域コード。 |
戻る
Direction - 呼び出しの連結を容易にする DirectionFinder オブジェクト。