Class ElevationSampler

ElevationSampler

Cho phép lấy mẫu độ cao tại các vị trí cụ thể.
Ví dụ bên dưới cho thấy cách bạn có thể sử dụng lớp này để xác định điểm cao nhất dọc theo tuyến đường từ Denver đến Grand Junction ở Colorado, vẽ điểm đó trên bản đồ và lưu bản đồ vào 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'),
);

Xem thêm

Phương thức

Phương thứcKiểu dữ liệu trả vềMô tả ngắn
sampleLocation(latitude, longitude)ObjectTrả về dữ liệu độ cao cho một điểm duy nhất (vĩ độ/kinh độ).
sampleLocations(points)ObjectTrả về dữ liệu độ cao cho một chuỗi điểm (vĩ độ/kinh độ).
sampleLocations(encodedPolyline)ObjectTrả về dữ liệu độ cao cho các điểm trong một đường nhiều đường được mã hoá.
samplePath(points, numSamples)ObjectTrả về dữ liệu độ cao cho một số mẫu dọc theo một đường thẳng, được xác định bằng cách sử dụng một chuỗi điểm.
samplePath(encodedPolyline, numSamples)ObjectTrả về dữ liệu độ cao cho một số mẫu dọc theo một đường thẳng, được xác định bằng cách sử dụng một chuỗi đa tuyến được mã hoá.

Tài liệu chi tiết

sampleLocation(latitude, longitude)

Trả về dữ liệu độ cao cho một điểm duy nhất (vĩ độ/kinh độ).

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

Thông số

TênLoạiMô tả
latitudeNumberVĩ độ của điểm cần lấy mẫu.
longitudeNumberKinh độ của điểm cần lấy mẫu.

Cầu thủ trả bóng

Object – Một đối tượng JSON chứa dữ liệu độ cao, như mô tả tại đây.


sampleLocations(points)

Trả về dữ liệu độ cao cho một chuỗi điểm (vĩ độ/kinh độ).

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

Thông số

TênLoạiMô tả
pointsNumber[]Một mảng gồm các cặp vĩ độ/kinh độ.

Cầu thủ trả bóng

Object – Một đối tượng JSON chứa dữ liệu độ cao, như mô tả tại đây.


sampleLocations(encodedPolyline)

Trả về dữ liệu độ cao cho các điểm trong một đường nhiều đường được mã hoá.

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

Thông số

TênLoạiMô tả
encodedPolylineStringMột đường nhiều đoạn được mã hoá gồm các điểm để lấy mẫu.

Cầu thủ trả bóng

Object – Một đối tượng JSON chứa dữ liệu độ cao, như mô tả tại đây.


samplePath(points, numSamples)

Trả về dữ liệu độ cao cho một số mẫu dọc theo một đường thẳng, được xác định bằng cách sử dụng một chuỗi điểm.

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

Thông số

TênLoạiMô tả
pointsNumber[]Một mảng gồm các cặp vĩ độ/kinh độ xác định đường dẫn để lấy mẫu.
numSamplesIntegerSố lượng điểm cần lấy mẫu dọc theo đường dẫn của các điểm.

Cầu thủ trả bóng

Object – Một đối tượng JSON chứa dữ liệu độ cao, như mô tả tại đây.


samplePath(encodedPolyline, numSamples)

Trả về dữ liệu độ cao cho một số mẫu dọc theo một đường thẳng, được xác định bằng cách sử dụng một chuỗi đa tuyến được mã hoá.

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

Thông số

TênLoạiMô tả
encodedPolylineStringMột chuỗi đa tuyến được mã hoá gồm các điểm xác định đường dẫn để lấy mẫu.
numSamplesIntegerSố lượng điểm cần lấy mẫu dọc theo đường dẫn của các điểm.

Cầu thủ trả bóng

Object – Một đối tượng JSON chứa dữ liệu độ cao, như mô tả tại đây.