这是我第一次在这里发帖,所以我非常感谢您的帮助。我已经在谷歌和这个网站上搜索过帮助,但没有找到任何像我正在寻找的东西。我正在尝试测量海拔高度
-(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 英尺为增量...
原始高度以米为单位,但我只是将其相乘以将其转换为英尺,所以我必须查看以米为单位的原始值吗?或者我可以查看海拔高度字段中的实际值吗?
我一直在尝试操作我发现的一些标准 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];
}
关于iphone - 如何对海拔执行 if else 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8302851/