如何在runkeeper应用程序中计算高程 [英] How to calculate elevation like in runkeeper application

查看:118
本文介绍了如何在runkeeper应用程序中计算高程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有跟踪用户移动的应用程序。并且我存储所有相关数据lat / lng / alt等。

我正在尝试添加提升,如 runkeeper 只是没有图形我需要获得高程值。

在我的.h文件中:

I have application that track user movement. And I store all relevant data lat/lng/alt etc.
I am trying add elevation like on runkeeper just without graphic I need just to get elevation value.
In my .h file:

@property (nonatomic) double netElevationLoss;
@property (nonatomic) double netElevationGain;
@property (nonatomic) double netElevationChange;

在我的.m文件中:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    double elevationChange = oldLocation.altitude - newLocation.altitude;
    if (elevationChange < 0)
    {
        netElevationLoss += fabs(elevationChange);
    }
    else
    {
        netElevationGain += elevationChange;
    }

    netElevationChange = netElevationGain - netElevationLoss;
...

我不知道这是计算它的正确方法。

我测试了它, alt 例如 182.53 netElevationChange -182.53

也许它很好,但也许我想知道我在这里做错了什么?

I don't know is this correct way to calculate it.
I have tested it and alt is for example 182.53 and netElevationChange is -182.53.
Maybe it's good but maybe I am missing something any idea what I have done wrong here?

推荐答案

根据您发布的维基百科文章,累积海拔增益基本上是所有海拔升高的总和。

According to the Wikipedia article you posted, "cumulative elevation gain" is basically the sum of all increases in elevation.

例如,假设你徒步100英尺,然后100英尺,然后200英尺,然后 250英尺(比如一个山谷),然后100英尺,你的增益将是100 + 200 + 150 = 450英尺。最后的150是由于在某个时间点升高到-50英尺,然后再升高100英尺。

So for example, say you hike 100 feet up, then 100 feet down, then 200 feet up, then 250 feet down (say, a valley), and then 100 feet up, your gain would be 100 + 200 + 150 = 450 feet. The last 150 is due to hiking to an elevation of -50 feet at some point, then 100 feet up again.

现在,这对你来说意味着你只是需要考虑高度增量,如下所示:

Now, what this means to you is that you simply need to take into account positive deltas of altitude, like so:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    double elevationChange = oldLocation.altitude - newLocation.altitude;

    // Only take into account positive changes
    if (elevationChange > 0)
    {
        netElevationGain += elevationChange;
    }
}

您甚至可以进一步简化:

You could even simplify it further:

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    netElevationGain += MAX(0, oldLocation.altitude - newLocation.altitude);
}

这将考虑山谷,甚至在攀登期间的跌宕起伏下降(应根据文章计算)。

This would take into account valleys and even "ups and downs" during ascent and descent (which should be counted according to the article).

最后, netElevationGain 属性将包含你的获利。

At the end, the netElevationGain property will contain your gain.

这篇关于如何在runkeeper应用程序中计算高程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆