Google Elevation Service API in feet

851 views Asked by At

I'm using the google elevation API to get elevation data along a path on google maps which I am then plotting on a google visualization column chart.

My code to get the data is as follows:

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


 });

The data returned is in Metric (Meters), how can I convert the returned elevation data to feet and then send that to the chart?

1

There are 1 answers

2
geocodezip On BEST ANSWER

To convert meters to feet, multiply by 3.28084 feet/meter

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