【问题标题】:how to perform if else statement on altitude如何在高度上执行 if else 语句
【发布时间】:2012-01-08 07:49:08
【问题描述】:

这是我第一次在这里发帖,非常感谢您的帮助。我已经搜索了谷歌以及这个网站寻求帮助,但没有找到与我正在寻找的东西非常相似的东西。我正在尝试海拔高度

-(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 英尺”之类的信息。我有另一个文本字段,我想根据altitudeField.text 中的高度值填写。如果海拔

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

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

【问题讨论】:

  • 你的意思是像 if (altitude.text == @"10.00 ft") {} 吗?
  • -(IBAction)calculate { float a = ([textField6.text floatValue]);浮动 h = ([textField2.text floatValue]);浮动 d = ([textField3.text floatValue]);浮动 f = (3600/[stopWatchField.text floatValue])*d; float s = ([textField4.text floatValue]); float r = ([textField5.text floatValue]);浮动 e = ([textField1.text floatValue]);浮动 c = ((e*(h*f))/((s-r)*a)); label2.text = [[[NSString alloc] initWithFormat:@"%.2f", f] autorelease]; label.text = [[[NSString alloc] initWithFormat:@"%.2f", c] autorelease]; }
  • 对不起,我不是故意要发布的,我按下回车键就发布了。但这就是我要发布的方程式。其中 [textField6.text floatValue] 将由 AltitudeField 决定。
  • @iBrad Apps:假设您尝试将字符串与“10.00 ft”进行比较,该功能不适用于您尝试执行的操作。在两个字符串上使用== 运算符将比较它们的指针值,并且只有当字符串是相同的字符串(在内存中,不一定在值中)时,它们才会传递该运算符并返回true。你会想要if([[altitude text] isEqualToString:@"10.00 ft"]) {}

标签: iphone ios core-location


【解决方案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];
}

【讨论】:

  • 非常感谢!这是我正在做的事情的完美起点。我一整天都在工作,试图让这一切顺利进行!这是我在工作中尝试的第一个应用程序,非常感谢您的帮助
  • 您应该在使用高度字段之前check if verticalAccuracy >= 0
【解决方案2】:

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

【讨论】:

  • 谢谢。我将开始使用它,因为高度会不断更新,因此存储该值并“if-else”关闭该存储值会更有意义。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-17
  • 2022-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多