iPhone Core Location: Calculate total elevation loss/gain

时光怂恿深爱的人放手 提交于 2019-12-09 21:05:04

问题


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.

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?

Ideas?


回答1:


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 

at any time.




回答2:


If you go up, increase one number. If you go down, increase (or decrease?) the other.

Exactly how you decide to handle noise is up to you...



来源:https://stackoverflow.com/questions/3928698/iphone-core-location-calculate-total-elevation-loss-gain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!