Class ElevationSampler

ElevationSampler

특정 위치에서 고도를 샘플링할 수 있습니다.
아래 예에서는 이 클래스를 사용하여 콜로라도주 덴버에서 그랜드 정션까지의 경로에서 가장 높은 지점을 확인하고, 지도에 표시하고, 지도를 Google Drive에 저장하는 방법을 보여줍니다.

// 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 객체입니다.