本文介绍了iPhone核心位置:计算总高程损失/增益的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在记录核心位置数据结束时计算总高程损失和增益。我很难想到这个数学的数学。

I am wanting to calculate total elevation loss and gain at the end of recording Core Location data. I am having a hard time thinking of the math for this one.

如果我在600英尺处开始并且在跟踪期间我上下移动,我将如何计算我的海拔增益和损失?

Say if I started at 600 feet and I go up and down during the tracking, how would I calculate my elevation gain and loss?

想法?

推荐答案

如果你想要分别跟踪收益和损失,保留两个累积成员变量netElevationLoss和netElevationGain,两者都初始化为0.

If you wanted to track gain and loss separately, keep two cumulative member variables, netElevationLoss and netElevationGain, both initialized to 0.

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    if(oldLocation == nil)
        return;

    double elevationChange = oldLocation.altitude - newLocation.altitude;
    if (elevationChange < 0)
    {
        netElevationLoss += fabs(elevationChange);
    }
    else
    {
        netElevationGain += elevationChange;
    }
}

您还可以使用此方法跟踪总变化,因为

You could also track total change using this method since

netElevationChange = netElevationGain - netElevationLoss 

随时。

这篇关于iPhone核心位置:计算总高程损失/增益的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 22:16