Class ElevationSampler

ElevationSampler

ช่วยให้สามารถสุ่มตัวอย่างระดับความสูงในบางสถานที่
ตัวอย่างด้านล่างแสดงวิธีการใช้คลาสนี้เพื่อหาจุดที่สูงที่สุดของเส้นทางจากเดนเวอร์ไปแกรนด์จังก์ชันในโคโลราโด วางผังบนแผนที่ และบันทึกแผนที่ลงใน Google ไดรฟ์

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

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

// Determine highest point.
var maxElevation = Number.MIN_VALUE;
var highestPoint = null;
for (var i = 0; i < response.results.length; i++) {
  var sample = response.results[i];
  if (sample.elevation > maxElevation) {
    maxElevation = sample.elevation;
    highestPoint = sample.location;
  }
}

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

// Save the map to your drive
DocsList.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.
var data = Maps.newElevationSampler().sampleLocation(40.759011, -73.984472);
Logger.log(data.results[0].elevation);

พารามิเตอร์

ชื่อTypeคำอธิบาย
latitudeNumberละติจูดของจุดที่จะสุ่มตัวอย่าง
longitudeNumberลองจิจูดของจุดที่จะสุ่มตัวอย่าง

รีเทิร์น

Object — ออบเจ็กต์ JSON ที่มีข้อมูลระดับความสูงตามที่อธิบายที่นี่


sampleLocations(points)

แสดงข้อมูลความสูงสำหรับชุดของจุด (ละติจูด/ลองจิจูด)

// Gets the elevation of Times Square and Central Park using points.
var 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);

พารามิเตอร์

ชื่อTypeคำอธิบาย
pointsNumber[]อาร์เรย์ของคู่ละติจูด/ลองจิจูด

รีเทิร์น

Object — ออบเจ็กต์ JSON ที่มีข้อมูลระดับความสูงตามที่อธิบายที่นี่


sampleLocations(encodedPolyline)

แสดงผลข้อมูลระดับความสูงของจุดในเส้นประกอบที่เข้ารหัส

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
encodedPolylineStringโพลีไลน์ที่เข้ารหัสเพื่อสุ่มตัวอย่าง

รีเทิร์น

Object — ออบเจ็กต์ JSON ที่มีข้อมูลระดับความสูงตามที่อธิบายที่นี่


samplePath(points, numSamples)

ส่งคืนข้อมูลระดับความสูงของจำนวนตัวอย่างตามเส้น ซึ่งระบุโดยใช้ชุดของจุด

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
pointsNumber[]อาร์เรย์ของคู่ละติจูด/ลองจิจูดที่กำหนดเส้นทางไปยังการสุ่มตัวอย่าง
numSamplesIntegerจำนวนของจุดที่จะสุ่มตัวอย่างตลอดเส้นทางของจุด

รีเทิร์น

Object — ออบเจ็กต์ JSON ที่มีข้อมูลระดับความสูงตามที่อธิบายที่นี่


samplePath(encodedPolyline, numSamples)

ส่งคืนข้อมูลระดับความสูงของจำนวนตัวอย่างตามเส้น ซึ่งระบุโดยใช้เส้นประกอบที่เข้ารหัส

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

พารามิเตอร์

ชื่อTypeคำอธิบาย
encodedPolylineStringโพลีไลน์ของจุดที่เข้ารหัสซึ่งกำหนดเส้นทางที่จะสุ่มตัวอย่าง
numSamplesIntegerจำนวนของจุดที่จะสุ่มตัวอย่างตลอดเส้นทางของจุด

รีเทิร์น

Object — ออบเจ็กต์ JSON ที่มีข้อมูลระดับความสูงตามที่อธิบายที่นี่