Google Elevation Service API 以英尺为单位

Google Elevation Service API in feet

本文关键字:为单位 API Elevation Service Google      更新时间:2023-09-26

我正在使用谷歌高程 API 沿谷歌地图上的路径获取高程数据,然后将其绘制在谷歌可视化柱形图上。

我获取数据的代码如下:

function createUpdateProfile(){
  var path=[];
  for (var i = 0; i < markers.length; i++) {
    path.push(markers[i].getPosition());
    };
  var elevator = new google.maps.ElevationService;
  // Draw the path, using the Visualization API and the Elevation service.
  displayPathElevation(path, elevator, map);
  }
function displayPathElevation(path, elevator, map) {
  elevator.getElevationAlongPath({
  'path': path,
  'samples': 256
  }, plotElevation);
  }
function plotElevation(elevations, status) {
 var chartDiv = document.getElementById('elevation_chart');
if (status !== google.maps.ElevationStatus.OK) {
 // Show the error code inside the chartDiv.
chartDiv.innerHTML = 'Cannot show elevation: request failed because ' +
    status;
 return;
 }
 // Create a new chart in the elevation_chart DIV.
 var chart = new google.visualization.ColumnChart(chartDiv);
 // Extract the data from which to populate the chart.
 // Because the samples are equidistant, the 'Sample'
 // column here does double duty as distance along the
 // X axis.
 var data = new google.visualization.DataTable();
 data.addColumn('string', 'Sample');
 data.addColumn('number', 'Elevation');
 for (var i = 0; i < elevations.length; i++) {
  data.addRow(['', elevations[i].elevation]);
}
 // Draw the chart using the data within its DIV.
 chart.draw(data, {
  height: 200,
 legend: 'none',
 titleY: 'Elevation (m)'

 });
返回

的数据采用公制(米)格式,如何将返回的高程数据转换为英尺,然后将其发送到图表?

要将米转换为英尺,请乘以 3.28084 英尺/米

for (var i = 0; i < elevations.length; i++) {
  data.addRow(['', elevations[i].elevation*3.28084]);
}