如何执行if else语句高度

时间:2011-11-28 21:50:05

标签: iphone ios core-location

这是我第一次在这里发帖,所以我非常感谢你的帮助。我搜索谷歌以及这个网站寻求帮助,但没有找到任何与我正在寻找的东西相似的东西。我正试图采取高度

-(void)locationManager:(CLLocationManager *)manager 
   didUpdateToLocation:(CLLocation *)newLocation 
          fromLocation:(CLLocation *)oldLocation
{
    altitudeField.text = [NSString stringWithFormat: @"%.2f ft", newLocation.altitude * 3.2808399];
}

-(void)locationManager:(CLLocationManager *)manager 
      didFailWithError:(NSError *)error
{
    altitudeField.text = @"0.00 ft";
}

这给了我类似于&#34; 500.00英尺&#34;例如。我有另一个文本域,我想根据altitudeField.text中的高度值填写。如果海拔高度<1000英尺,它在textField6中等于1.08,从1000到2000英尺,在textField6中等于1.04,依此类推,以1000英尺为增量...

原始高度以米为单位,但我只是将其乘以将其变为英尺,所以我必须以米为单位查看原始值吗?或者我可以查看altitudeField中的实际值吗?

我一直试图操纵我找到的一些标准的if-else语句,但我得到的只是错误。任何帮助或方向将不胜感激。

2 个答案:

答案 0 :(得分:1)

为什么不这样做:

-(void)locationManager:(CLLocationManager *)manager 
   didUpdateToLocation:(CLLocation *)newLocation 
          fromLocation:(CLLocation *)oldLocation
{
    double altitudeFt = newLocation.altitude * 3.2808399;
    altitudeField.text = [NSString stringWithFormat: @"%.2f ft", altitudeFt];
    double otherValue = 1.08 - 0.4 * floor(altitudeFt / 1000);
    otherField.text = [NSString stringWithFormat:@"%.2f", otherValue];
}

答案 1 :(得分:0)

听起来你需要创建一个变量来存储海拔高度的数值。然后,您可以在设置特定字段的文本时进行必要的调整/转换/格式化。