0

我有这个功能可以输出特定路线期间的总海拔增益和下降。我还想导出该段的平均坡度(即斜率)。我是否使用方程 m = 上升/运行?我将如何实施呢?

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;
};

更新:我想将其与计算路线的函数联系起来:

var from = new google.maps.LatLng(40.750484, -111.811177);
var to = new google.maps.LatLng(40.775041, -111.718560);

     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);
        }
    }); 
4

1 回答 1

0

从这篇文章 ( http://www.daftlogic.com/sandbox-google-maps-find-altitude.htm ) 中可以看出,您可以使用它getElevationByLocations来执行此操作。

这是主要部分,但您可能需要通读代码以了解如何使用它:

elevator.getElevationForLocations(positionalRequest, function(results, status) 
{
if (status == google.maps.ElevationStatus.OK) 
{
// Retrieve the first result
if (results[0]) 
{
// Open an info window indicating the elevation at the clicked position
outputDiv.innerHTML= "Last point clicked : " + results[0].elevation.toFixed(3) + " m";

这是此功能的文档:

https://developers.google.com/maps/documentation/javascript/elevation

因此,只需确定每个标记处的高程,然后使用您的公式来获得高程变化,但请务必指出这是一个平均值,因为它可能会在两点之间发生很大变化,但平均而言,要平坦。

于 2013-09-14T21:48:01.913 回答