0

This is my first time posting here so I would greatly appreciate the help. I have searched Google as well as this site for help and have not found anything quite like what I am looking for. I am trying to take the altitude

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

Which gives me something like "500.00 ft" for instance. I have another textfield that I would like to fill in based on the altitude value in altitudeField.text. Where if the altitude is <1000 ft it equals 1.08 in textField6, from 1000 to 2000 ft it equals 1.04 in textField6, and so on in 1000 ft increments...

The original altitude is in meters, but I just multiply it to get it into feet, so must I look at the original value in meters? Or can I look at the actual value in the altitudeField?

I have been trying to manipulate some standard if-else statements I have found but I get nothing but errors. Any help or direction would be greatly appreciated.

Bert
  • 80,741
  • 17
  • 199
  • 164
  • Do you mean something like if (altitude.text == @"10.00 ft") {} ? – SimplyKiwi Nov 28 '11 at 21:53
  • -(IBAction)calculate { float a = ([textField6.text floatValue]); float h = ([textField2.text floatValue]); float d = ([textField3.text floatValue]); float f = (3600/[stopWatchField.text floatValue])*d; float s = ([textField4.text floatValue]); float r = ([textField5.text floatValue]); float e = ([textField1.text floatValue]); float c = ((e*(h*f))/((s-r)*a)); label2.text = [[[NSString alloc] initWithFormat:@"%.2f", f] autorelease]; label.text = [[[NSString alloc] initWithFormat:@"%.2f", c] autorelease]; } – coryb10487 Nov 28 '11 at 21:59
  • sorry, i didn't mean to post that yet, I pressed enter and it posted. But that is the equation I am looking to post it in. where [textField6.text floatValue] would be decided by the altitudeField. – coryb10487 Nov 28 '11 at 22:01
  • @iBrad Apps: that function won't work for what you are trying to do, assuming you are attempting to compare the string to "10.00 ft". Using the `==` operator on two strings will compare their pointer value, and only if the string is the same string (in memory, not necessarily in value) will they pass that operator and return true. You would want something like `if([[altitude text] isEqualToString:@"10.00 ft"]) {}` – ColdLogic Nov 28 '11 at 22:44

2 Answers2

1

Why not just do this:

-(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];
}
rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • thank you very much! that is the perfect starting point for what I am doing. I have been pulling my hair out all day at work trying to get this going! This is my first app we are trying here at work and the help is very much appreciated – coryb10487 Nov 28 '11 at 22:21
  • you should [check if verticalAccuracy >= 0](http://stackoverflow.com/q/7402503/154803) before using the altitude field – progrmr Nov 30 '11 at 16:43
0

It sounds like you need to create a variable to store the numeric value of your altitude. You can then make what ever adjustments/conversions/formatting necessary when you set a particular field's text.

Dancreek
  • 9,524
  • 1
  • 31
  • 34
  • Thank you. I will start working with that as the altitude is constantly updating so it would make more sense to store that value and "if-else" off that stored value. – coryb10487 Nov 28 '11 at 22:02