Class DirectionFinder

DirectionFinder

地点間のルートを取得できます。
以下の例では、このクラスを使用して、タイムズ スクエアからセントラル パークまでの経路を検索し、まずリンカーン センターを経由し、場所と経路を地図上に表示して、メールで送信する方法を示しています。

// Get the directions.
var 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();
var route = directions.routes[0];

// Set up marker styles.
var markerSize = Maps.StaticMap.MarkerSize.MID;
var markerColor = Maps.StaticMap.Color.GREEN
var markerLetterCode = 'A'.charCodeAt();

// Add markers to the map.
var map = Maps.newStaticMap();
for (var i = 0; i < route.legs.length; i++) {
  var leg = route.legs[i];
  if (i == 0) {
    // Add a marker for the start location of the first leg only.
    map.setMarkerStyle(markerSize, markerColor, String.fromCharCode(markerLetterCode));
    map.addMarker(leg.start_location.lat, leg.start_location.lng);
    markerLetterCode++;
  }
  map.setMarkerStyle(markerSize, markerColor, 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.
var 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')
    }
  }
);

関連ドキュメント

Methods

メソッド戻り値の型概要
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.
var directionFinder = Maps.newDirectionFinder().addWaypoint(40.772628, -73.984243);

パラメータ

名前説明
latitudeNumberウェイポイントの緯度。
longitudeNumber地点の経度。

リターン

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


addWaypoint(address)

住所を使用して、経路が通過する地点を追加します。

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

パラメータ

名前説明
addressString住所。

リターン

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


clearWaypoints()

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

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

リターン

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


getDirections()

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

// Logs how long it would take to walk from Times Square to Central Park.
var 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 alernative routes enabled.
var directionFinder = Maps.newDirectionFinder().setAlternatives(true);

パラメータ

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

リターン

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


setArrive(time)

希望する到着時刻を設定します(該当する場合)。

// Creates a DirectionFinder with an arrival time of 2 hours from now.
var now = new Date();
var arrive = new Date(now.getTime() + (2 * 60 * 60 * 1000));
var directionFinder = Maps.newDirectionFinder().setArrive(arrive);

パラメータ

名前説明
timeDate到着時刻

リターン

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

関連ドキュメント


setAvoid(avoid)

特定のタイプの制限を回避するかどうかを設定します。

// Creates a DirectionFinder that avoid highways.
var 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.
var now = new Date();
var depart = new Date(now.getTime() + (1 * 60 * 60 * 1000));
var directionFinder = Maps.newDirectionFinder().setDepart(depart);

パラメータ

名前説明
timeDate出発時刻

リターン

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

関連ドキュメント


setDestination(latitude, longitude)

地点(緯度/経度)を使って、ルートを計算する目的地を設定します。

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

パラメータ

名前説明
latitudeNumber目的地の緯度
longitudeNumber目的地の経度

リターン

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


setDestination(address)

住所を使って、ルートを計算する目的地を設定します。

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

パラメータ

名前説明
addressString終点アドレス

リターン

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


setLanguage(language)

ルートに使用する言語を設定します。

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

パラメータ

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

リターン

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

関連ドキュメント


setMode(mode)

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

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

パラメータ

名前説明
modeStringMode からの定数値

リターン

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

関連ドキュメント


setOptimizeWaypoints(optimizeOrder)

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

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

パラメータ

名前説明
optimizeOrderBoolean順序を最適化する場合は true、そうでない場合は false です。

リターン

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

関連ドキュメント


setOrigin(latitude, longitude)

地点(緯度/経度)を使用して、ルートの計算を開始する地点を設定します。

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

パラメータ

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

リターン

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


setOrigin(address)

住所を使用して、ルートの計算の出発地を設定します。

// Creates a DirectionFinder with the origin set to Times Square.
var 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.
var directionFinder = Maps.newDirectionFinder().setRegion('fr');

パラメータ

名前説明
regionStringリージョン コードを指定します。

リターン

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

関連ドキュメント