ช่วยให้สามารถสุ่มตัวอย่างระดับความสูงในสถานที่ตั้งที่เฉพาะเจาะจง
ตัวอย่างด้านล่างแสดงวิธีใช้คลาสนี้เพื่อระบุจุดที่สูงที่สุดตามเส้นทางจากเดนเวอร์ไปยังแกรนด์จังก์ชันในโคโลราโด วางแผนบนแผนที่ และบันทึกแผนที่ลงใน 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'), );
ดูเพิ่มเติม
เมธอด
| วิธีการ | ประเภทการแสดงผล | รายละเอียดแบบย่อ |
|---|---|---|
sample | Object | แสดงผลข้อมูลระดับความสูงสำหรับจุดเดียว (lat/lng) |
sample | Object | แสดงผลข้อมูลระดับความสูงสำหรับชุดจุด (ละติจูด/ลองจิจูด) |
sample | Object | แสดงผลข้อมูลระดับความสูงสำหรับจุดในโพลีไลน์ที่เข้ารหัส |
sample | Object | แสดงผลข้อมูลระดับความสูงสำหรับตัวอย่างจำนวนหนึ่งตามแนวเส้นที่กำหนดโดยใช้ชุดจุด |
sample | Object | แสดงผลข้อมูลระดับความสูงสำหรับตัวอย่างจำนวนหนึ่งตามแนวเส้นที่กำหนดโดยใช้ Polyline ที่เข้ารหัส |
เอกสารโดยละเอียด
sample Location(latitude, longitude)
แสดงผลข้อมูลระดับความสูงสำหรับจุดเดียว (lat/lng)
// Gets the elevation of Times Square using a point. const data = Maps.newElevationSampler().sampleLocation(40.759011, -73.984472); Logger.log(data.results[0].elevation);
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
latitude | Number | ละติจูดของจุดที่จะสุ่มตัวอย่าง |
longitude | Number | ลองจิจูดของจุดที่จะสุ่มตัวอย่าง |
รีเทิร์น
Object — ออบเจ็กต์ JSON ที่มีข้อมูลระดับความสูง ดังที่อธิบายไว้ที่นี่
sample Locations(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}`);
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
points | Number[] | อาร์เรย์ของคู่ละติจูด/ลองจิจูด |
รีเทิร์น
Object — ออบเจ็กต์ JSON ที่มีข้อมูลระดับความสูง ดังที่อธิบายไว้ที่นี่
sample Locations(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}`);
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
encoded | String | เส้นหลายเส้นที่เข้ารหัสของจุดที่จะสุ่มตัวอย่าง |
รีเทิร์น
Object — ออบเจ็กต์ JSON ที่มีข้อมูลระดับความสูง ดังที่อธิบายไว้ที่นี่
sample Path(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); }
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
points | Number[] | อาร์เรย์ของคู่ละติจูด/ลองจิจูดที่กำหนดเส้นทางที่จะสุ่มตัวอย่าง |
num | Integer | จำนวนจุดที่จะสุ่มตัวอย่างตามเส้นทางของจุด |
รีเทิร์น
Object — ออบเจ็กต์ JSON ที่มีข้อมูลระดับความสูง ดังที่อธิบายไว้ที่นี่
sample Path(encodedPolyline, numSamples)
แสดงผลข้อมูลระดับความสูงสำหรับตัวอย่างจำนวนหนึ่งตามแนวเส้นที่กำหนดโดยใช้ Polyline ที่เข้ารหัส
// 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); }
พารามิเตอร์
| ชื่อ | ประเภท | คำอธิบาย |
|---|---|---|
encoded | String | เส้นประกอบที่เข้ารหัสของจุดที่กำหนดเส้นทางที่จะสุ่มตัวอย่าง |
num | Integer | จำนวนจุดที่จะสุ่มตัวอย่างตามเส้นทางของจุด |
รีเทิร์น
Object — ออบเจ็กต์ JSON ที่มีข้อมูลระดับความสูง ดังที่อธิบายไว้ที่นี่