Class ElevationSampler

ElevationSampler

特定の場所の標高をサンプリングできます。
次の例では、このクラスを使用して、コロラド州デンバーからグランドジャンクションまでのルート上の最高地点を特定し、地図上にプロットして、その地図を Google ドライブに保存する方法を示します。

// Get directions from Denver to Grand Junction.
const directions = Maps.newDirectionFinder()
                       .setOrigin('Denver, CO')
                       .setDestination('Grand Junction, CO')
                       .setMode(Maps.DirectionFinder.Mode.DRIVING)
                       .getDirections();
const route = directions.routes[0];

// Get elevation samples along the route.
const numberOfSamples = 30;
const response = Maps.newElevationSampler().samplePath(
    route.overview_polyline.points,
    numberOfSamples,
);

// Determine highest point.

let highestLocation = null;
let highestElevation = Number.MIN_VALUE;
for (const sample of response.results) {
  if (sample.elevation > highestElevation) {
    highestElevation = sample.elevation;
    highestLocation = sample.location;
  }
}

// Add the path and marker to a map.
const map = Maps.newStaticMap()
                .addPath(route.overview_polyline.points)
                .addMarker(highestLocation.lat, highestLocation.lng);

// Save the map to your drive
DriveApp.createFile(
    Utilities.newBlob(map.getMapImage(), 'image/png', 'map.png'),
);

関連情報

メソッド

メソッド戻り値の型概要
sampleLocation(latitude, longitude)Object単一点(緯度/経度)の標高データを返します。
sampleLocations(points)Object一連の点(緯度/経度)の標高データを返します。
sampleLocations(encodedPolyline)Objectエンコードされたポリライン内の点の標高データを返します。
samplePath(points, numSamples)Object一連の点を使用して定義された線に沿ったサンプル数の標高データを返します。
samplePath(encodedPolyline, numSamples)Objectエンコードされたポリラインを使用して定義された線に沿ったサンプル数の標高データを返します。

詳細なドキュメント

sampleLocation(latitude, longitude)

単一点(緯度/経度)の標高データを返します。

// Gets the elevation of Times Square using a point.
const data = Maps.newElevationSampler().sampleLocation(40.759011, -73.984472);
Logger.log(data.results[0].elevation);

パラメータ

名前タイプ説明
latitudeNumberサンプリングする点の緯度。
longitudeNumberサンプリングする点の経度。

戻る

Object \- 標高データを含む JSON オブジェクト。詳細については、こちらをご覧ください。


sampleLocations(points)

一連の点(緯度/経度)の標高データを返します。

// Gets the elevation of Times Square and Central Park using points.
const data = Maps.newElevationSampler().sampleLocations([
  // Times Square
  40.759011,
  -73.984472,
  // Central Park
  40.777052,
  -73.975464,
]);
Logger.log(`Times Square: ${data.results[0].elevation}`);
Logger.log(`Central Park: ${data.results[1].elevation}`);

パラメータ

名前タイプ説明
pointsNumber[]緯度と経度のペアの配列。

戻る

Object \- 標高データを含む JSON オブジェクト。詳細については、こちらをご覧ください。


sampleLocations(encodedPolyline)

エンコードされたポリライン内の点の標高データを返します。

// Gets the elevation of Times Square and Central Park using a polyline.
const data = Maps.newElevationSampler().sampleLocations('yvwwF|aqbMwoBiw@');
Logger.log(`Times Square: ${data.results[0].elevation}`);
Logger.log(`Central Park: ${data.results[1].elevation}`);

パラメータ

名前タイプ説明
encodedPolylineStringサンプリングする点のエンコードされたポリライン。

戻る

Object \- 標高データを含む JSON オブジェクト。詳細については、こちらをご覧ください。


samplePath(points, numSamples)

一連の点を使用して定義された線に沿ったサンプル数の標高データを返します。

// Gets the elevation of five points between Times Square and Central Park.
const data = Maps.newElevationSampler().samplePath(
    [
      // Times Square
      40.759011,
      -73.984472,
      // Central Park
      40.777052,
      -73.975464,
    ],
    5,
);
for (let i = 0; i < data.results.length; i++) {
  Logger.log(data.results[i].elevation);
}

パラメータ

名前タイプ説明
pointsNumber[]サンプリングするパスを定義する緯度と経度のペアの配列。
numSamplesInteger点のパスに沿ってサンプリングする点の数。

戻る

Object \- 標高データを含む JSON オブジェクト。詳細については、こちらをご覧ください。


samplePath(encodedPolyline, numSamples)

エンコードされたポリラインを使用して定義された線に沿ったサンプル数の標高データを返します。

// Gets the elevation of five points between Times Square and Central Park.
const data = Maps.newElevationSampler().samplePath('yvwwF|aqbMwoBiw@', 5);
for (let i = 0; i < data.results.length; i++) {
  Logger.log(data.results[i].elevation);
}

パラメータ

名前タイプ説明
encodedPolylineStringサンプリングするパスを定義する点のエンコードされたポリライン。
numSamplesInteger点のパスに沿ってサンプリングする点の数。

戻る

Object \- 標高データを含む JSON オブジェクト。詳細については、こちらをご覧ください。