【问题标题】:How to Calculate elevation from gps altitude in flutter如何从颤动中的gps高度计算海拔高度
【发布时间】:2020-08-27 10:06:43
【问题描述】:

大家好,我需要帮助我正在跟踪应用程序并想要计算总海拔增益。我正在从位置拉高但无法计算旅行期间的总海拔增益我将所有海拔值保存在列表中。所以基本上需要一个公式来提供旅行期间的总海拔增益。 像这样在颤动中拉高程

海拔 = location.coords.altitude.toString();

【问题讨论】:

  • 在旅行开始时获取海拔并存储在变量中。然后在将每个海拔高度存储在列表中的同时,从旅行开始时记录的海拔高度中减去海拔高度,然后取海拔高度列表的平均值。
  • @AdithyaShetty 任何代码参考或代码片段都会非常感谢!谢谢!
  • 是的,为什么不呢。但是你能确认所有海拔的平均值是你的目标吗?
  • 我正在添加一个答案,以获得旅行开始时的平均海拔高度。
  • 你好@AdithyaShetty!非常感谢您的回复。是的,我想要高程增益,例如高程上升而不是高程下降

标签: flutter gps tracking


【解决方案1】:

请阅读以了解代码

我们正在比较三个海拔点:

我们举个例子,用户启动时的海拔是100m

例如:700m,1000m,800 中的三个标高。 以上三个高程表示用户到达1000m后进行了下降。所以对于仰角增益是1000-100m = 900m,这是真正的仰角增益。其中减去的 100m 是行程开始时记录的海拔高度。


现在让我们考虑接下来的三个海拔是 800m,600m,700m 这表明在下降到 600m 后用户再次开始攀登。

所以现在真正的下降将计算用户从 1000m 下降了多少,因此真正的下降将是 1000m-600m =400m

代码块中的 cmets 解释了每个步骤在做什么。


// This jut stimulates elevations in a small trip
  // instead of this list call the functions whenever you record a elevation.
  // and on the end of the trip call the [onStopTrip] function.
  List<double> listOfDemoElevations = [
    200.0, 300.0,400.0,1000.0,800.0,700.0,600.0,500.0,600.0,800.0,300.0,200.0];
  
  ///This Code Snippet compares Elevation of three points to see if the person has started ascending or is descending.
  /// Then the code only stores the point after which user asecded or descended.
  /// Then Calulates the total Elevation Gain or Elevation Loss.
  
  double elevationGain = 0.0;
  double elevationLoss = 0.0;
  double startTripElevation = 100.0; //Record the StartTripElevation;
  double previousElevation = startTripElevation;
  double beforePreviousElevation = startTripElevation;
  double adjustment =startTripElevation ; // this to get the truw ascend or descend

  
  // This function check the three elevation then adds to elevation gain or loss accordinly with adjustment so true elevation gain or loss is recorded.
  void calculateElevationGainLoss(double currentElevation) {
    if (beforePreviousElevation < previousElevation &&
        previousElevation > currentElevation) {
      elevationGain = elevationGain + (previousElevation - adjustment);
      adjustment = previousElevation;
    } else if (beforePreviousElevation > previousElevation &&
        currentElevation > previousElevation) {
      elevationLoss = elevationLoss + (adjustment - previousElevation);
      adjustment = previousElevation;
    }
    beforePreviousElevation = previousElevation;
    previousElevation = currentElevation;
  }

  /// this function check if the elevation at which the user ended the trip to be added to elevation gain or loss
  void onStopTrip(double currentElevation) {
    if (adjustment > currentElevation) {
      elevationLoss = elevationLoss + (adjustment - currentElevation);
    } else if (adjustment < currentElevation) {
      elevationGain = elevationGain + (currentElevation - adjustment);
    }

    
  }

  listOfDemoElevations.forEach((element) {
    calculateElevationGainLoss(element);
  });

  // Call this function when user hits end trip
  onStopTrip(listOfDemoElevations.last);

  print('Elevation gain=$elevationGain');
  print('Elevation loss=$elevationLoss');

您可以将整个代码放入 dartpad 中的void main{} 中并进行测试:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-03-04
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 1970-01-01
    • 2014-12-30
    • 2018-10-03
    • 1970-01-01
    相关资源
    最近更新 更多