Google Elevation Service API英尺

时间:2016-02-04 14:17:38

标签: javascript jquery google-maps google-visualization google-elevation-api

我使用Google提升API在google地图上的路径上获取高程数据,然后我将其绘制在Google可视化柱形图上。

获取数据的代码如下:

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)'


 });

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

1 个答案:

答案 0 :(得分:0)

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

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