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