如何对海拔执行if else语句



这是我第一次在这里发帖,所以我将非常感谢帮助。我已经搜索了谷歌以及这个网站的帮助,并没有找到任何东西很像我正在寻找。我正试着测量海拔

-(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";
}
例如,

给出的结果是"500.00 ft"。我有另一个文本字段,我想根据altitudeField.text中的高度值来填充它。其中,如果高度为<1000英尺,则在textField6中等于1.08,从1000英尺到2000英尺,则在textField6中等于1.04,依次递增1000英尺…

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

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

为什么不这样做呢:

-(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];
}

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

最新更新