Class DirectionFinder

DirectionFinder

地点間のルートを取得できます。
次の例は、このクラスを使用してタイムズ スクエアからセントラル パークまでのルートを取得し、最初にリンカーン センターに立ち寄って、地図上に場所と経路をプロットし、地図をメールで送信する方法を示しています。

// 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'),
      },
    },
);

関連情報

メソッド

メソッド戻り値の型概要
addWaypoint(latitude, longitude)DirectionFinderポイント(緯度/経度)を使用して、ルートが通過する必要がある経由地を追加します。
addWaypoint(address)DirectionFinder住所を使用して、ルートが通過する必要がある経由地を追加します。
clearWaypoints()DirectionFinder現在の経由地のセットをクリアします。
getDirections()Object設定された出発地、目的地、その他のオプションを使用してルートを取得します。
setAlternatives(useAlternatives)DirectionFinderランク付けが最も高いルートだけでなく、代替ルートも返すかどうかを設定します(デフォルトは false)。
setArrive(time)DirectionFinder希望する到着時刻を設定します(該当する場合)。
setAvoid(avoid)DirectionFinder特定の種類の制限を回避するかどうかを設定します。
setDepart(time)DirectionFinderご希望の出発時刻を設定します(該当する場合)。
setDestination(latitude, longitude)DirectionFinderポイント(緯度/経度)を使用して、ルートを計算する終了地点を設定します。
setDestination(address)DirectionFinder住所を使用して、経路を計算する終了地点を設定します。
setLanguage(language)DirectionFinderルート案内で使用する言語を設定します。
setMode(mode)DirectionFinder移動手段を設定します(デフォルトは運転)。
setOptimizeWaypoints(optimizeOrder)DirectionFinder地点をより効率的な順序に並べ替えて、指定されたルートを最適化するかどうかを設定します(デフォルトは false)。
setOrigin(latitude, longitude)DirectionFinderポイント(緯度/経度)を使用して、ルートを計算する出発地を設定します。
setOrigin(address)DirectionFinder住所を使用して、経路を計算する出発地を設定します。
setRegion(region)DirectionFinder位置情報の名前を解釈する際に使用する地域を設定します。

詳細なドキュメント

addWaypoint(latitude, longitude)

ポイント(緯度/経度)を使用して、ルートが通過する必要がある経由地を追加します。

// Creates a DirectionFinder with a wapoint at Lincoln Center.
const directionFinder = Maps.newDirectionFinder().addWaypoint(
    40.772628,
    -73.984243,
);

パラメータ

名前説明
latitudeNumber経由地の緯度。
longitudeNumber経由地の経度。

戻る

DirectionFinder - 呼び出しの連結を容易にする DirectionFinder オブジェクト。


addWaypoint(address)

住所を使用して、ルートが通過する必要がある経由地を追加します。

// Creates a DirectionFinder with a wapoint at Lincoln Center.
const directionFinder = Maps.newDirectionFinder().addWaypoint(
    'Lincoln Center, New York, NY',
);

パラメータ

名前説明
addressString住所。

戻る

DirectionFinder - 呼び出しの連結を容易にする DirectionFinder オブジェクト。


clearWaypoints()

現在の経由地セットをクリアします。

const directionFinder = Maps.newDirectionFinder();
// ...
// Do something interesting here ...
// ...
// Remove all waypoints added with addWaypoint().
directionFinder.clearWaypoints();

戻る

DirectionFinder - 呼び出しの連結を容易にする DirectionFinder オブジェクト。


getDirections()

設定された出発地、目的地、その他のオプションを使用してルートを取得します。

// 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 オブジェクト。

関連情報


setAlternatives(useAlternatives)

ランク付けが最も高いルートのみではなく、代替ルートを返すかどうかを設定します(デフォルトは false)。true の場合、結果オブジェクトの routes 配列に複数のエントリが含まれることがあります。

// Creates a DirectionFinder with alternative routes enabled.
const directionFinder = Maps.newDirectionFinder().setAlternatives(true);

パラメータ

名前説明
useAlternativesBoolean代替ルートを返す場合は true、それ以外の場合は false

戻る

DirectionFinder - 呼び出しの連結を容易にする DirectionFinder オブジェクト。


setArrive(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);

パラメータ

名前説明
timeDate到着時刻。

戻る

DirectionFinder - 呼び出しの連結を容易にする DirectionFinder オブジェクト。

関連情報


setAvoid(avoid)

特定の種類の制限を回避するかどうかを設定します。

// Creates a DirectionFinder that avoid highways.
const directionFinder = Maps.newDirectionFinder().setAvoid(
    Maps.DirectionFinder.Avoid.HIGHWAYS,
);

パラメータ

名前説明
avoidStringAvoid の定数値。

戻る

DirectionFinder - 呼び出しの連結を容易にする DirectionFinder オブジェクト。

関連情報


setDepart(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);

パラメータ

名前説明
timeDate出発時刻。

戻る

DirectionFinder - 呼び出しのチェーンを容易にする DirectionFinder オブジェクト。

関連情報


setDestination(latitude, longitude)

ポイント(緯度/経度)を使用して、ルートを計算する終了地点を設定します。

// Creates a DirectionFinder with the destination set to Central Park.
const directionFinder = Maps.newDirectionFinder().setDestination(
    40.777052,
    -73.975464,
);

パラメータ

名前説明
latitudeNumber終了地点の緯度。
longitudeNumber終了地点の経度。

戻る

DirectionFinder - 呼び出しのチェーンを容易にする DirectionFinder オブジェクト。


setDestination(address)

住所を使用して、経路を計算する終了地点を設定します。

// Creates a DirectionFinder with the destination set to Central Park.
const directionFinder = Maps.newDirectionFinder().setDestination(
    'Central Park, New York, NY',
);

パラメータ

名前説明
addressString終了アドレス。

戻る

DirectionFinder - 呼び出しのチェーンを容易にする DirectionFinder オブジェクト。


setLanguage(language)

ルート案内で使用する言語を設定します。

// Creates a DirectionFinder with the language set to French.
const directionFinder = Maps.newDirectionFinder().setLanguage('fr');

パラメータ

名前説明
languageStringBCP-47 言語識別子。

戻る

DirectionFinder - 呼び出しの連結を容易にする DirectionFinder オブジェクト。

関連情報


setMode(mode)

移動手段を設定します(デフォルトは運転)。

// Creates a DirectionFinder with the mode set to walking.
const directionFinder = Maps.newDirectionFinder().setMode(
    Maps.DirectionFinder.Mode.WALKING,
);

パラメータ

名前説明
modeStringMode の定数値。

戻る

DirectionFinder - 呼び出しの連結を容易にする DirectionFinder オブジェクト。

関連情報


setOptimizeWaypoints(optimizeOrder)

地点をより効率的な順序に並べ替えて、指定されたルートを最適化するかどうかを設定します(デフォルトは false)。

// Creates a DirectionFinder with wapoint optimization enabled.
const directionFinder = Maps.newDirectionFinder().setOptimizeWaypoints(true);

パラメータ

名前説明
optimizeOrderBoolean注文を最適化する場合は true、それ以外の場合は false

戻る

DirectionFinder - 呼び出しの連結を容易にする DirectionFinder オブジェクト。

関連情報


setOrigin(latitude, longitude)

ポイント(緯度/経度)を使用して、ルートを計算する出発地を設定します。

// Creates a DirectionFinder with the origin set to Times Square.
const directionFinder = Maps.newDirectionFinder().setOrigin(
    40.759011,
    -73.984472,
);

パラメータ

名前説明
latitudeNumber出発地の緯度。
longitudeNumber出発地の経度。

戻る

DirectionFinder - 呼び出しの連結を容易にする DirectionFinder オブジェクト。


setOrigin(address)

住所を使用して、経路を計算する出発地を設定します。

// Creates a DirectionFinder with the origin set to Times Square.
const directionFinder = Maps.newDirectionFinder().setOrigin(
    'Times Square, New York, NY',
);

パラメータ

名前説明
addressString開始アドレス。

戻る

DirectionFinder - 呼び出しのチェーンを容易にする DirectionFinder インスタンス。


setRegion(region)

位置情報の名前を解釈する際に使用する地域を設定します。サポートされている地域コードは、Google マップでサポートされている ccTLD に対応しています。たとえば、地域コード「uk」は「maps.google.co.uk」に対応します。

// Creates a DirectionFinder with the region set to France.
const directionFinder = Maps.newDirectionFinder().setRegion('fr');

パラメータ

名前説明
regionString使用する地域コード。

戻る

DirectionFinder - 呼び出しの連結を容易にする DirectionFinder オブジェクト。

関連情報