0

This is only a snippet of code, from my project, but it is currently showing a map and an elevation bar. The elevation bar is currently showing metric, instead of imperial. Clearly, I have defined imperial. Any ideas?

     ds.route({
  origin: from,
  destination: to,
  travelMode: google.maps.DirectionsTravelMode.DRIVING,
  unitSystem: google.maps.UnitSystem.IMPERIAL
}, function(result, status) {
  if (status == google.maps.DirectionsStatus.OK) {
      fitBounds = true;
      dr.setDirections(result);
    }
}); 

Update: Does this information get passed along to google's elevation service? It seems like if you define imperial here, it should carry through.

4

1 回答 1

2

您的代码返回海拔米。要将其转换为 IMPERIAL,以下将米转换为英尺。

var writeStats = function(r) {
  var prevElevation = r[0].elevation;
  var climb = 0;
  var drop = 0;
  var max = 0;
  for (var i = 1; i < r.length; i++) {
    var diff = r[i].elevation - prevElevation;
    prevElevation = r[i].elevation;
    if (diff > 0) {
      climb += diff;
      climb = Math.abs(climb / 1) ;//Object to number
      var  climb2 = climb  * 3.2808399;//Metres to feet

    }
    else {
      drop -= diff;
      drop = Math.abs(drop / 1) ;
      var  drop2 = drop  * 3.2808399;

    }

    if (r[i].elevation > max) {
      max = r[i].elevation;
    }
  }
  max = Math.ceil(max);
  $('#climb-drop').text("Climb: " + Math.round(climb2) + " feet Drop: " + Math.round(drop2) + " feet");
  return max;
};

在此处输入图像描述

于 2013-09-13T18:49:10.827 回答