【问题标题】:Google Elevation Service API in feet以英尺为单位的 Google Elevation Service API
【发布时间】:2016-05-14 04:56:18
【问题描述】:

我正在使用谷歌海拔 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)'


 });

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

【问题讨论】:

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


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回复。我经常使用你的网站作为谷歌地图参考!我试过了,我得到了以下错误:“未捕获的错误:如果为 addRow 提供参数,它必须是一个数组,或者为空”
    • 非常感谢!!如果您可以查看我在 SO 上的另一个问题,该问题与您网站上的代码相同,我将非常感激。 stackoverflow.com/questions/35133899/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多