views:

1034

answers:

2

Hello Stacked-Experts!

My question: How to generate a string from a CLLocationDegrees value?

Failed attempts:

1. NSLog(@"Value: %f", currentLocation.coordinate.latitude); //Tried with all NSLog specifiers.
2. NSNumber *tmp = [[NSNumber alloc] initWithDouble:currentLocation.coordinate.latitude];
3. NSString *tmp = [[NSString alloc] initWithFormat:@"%@", currentLocation.coordinate.latitude];

When I look in the definition for the CLLocationDegrees it clearly states that this is a double:

typedef double CLLocationDegrees;

What am I missing here? This is making me go crazy... Please help to save my mind!

Thanks in advance and best regards. //Abeansits

+1  A: 

These are correct: NSLog(@"Value: %f", currentLocation.coordinate.latitude); //Tried with all NSLog specifiers. 2. NSNumber *tmp = [[NSNumber alloc] initWithDouble:currentLocation.coordinate.latitude];

This is wrong, because coordinate.latitude isn't an object as nsstring might expect. 3. NSString *tmp = [[NSString alloc] initWithFormat:@"%@", currentLocation.coordinate.latitude];

If you want an NSString: myString = [[NSNumber numberWithDouble:currentLocation.coordinate.latitude] stringValue];

or: NSString *tmp = [[NSString alloc] initWithFormat:@"%f", currentLocation.coordinate.latitude];

Marco

Marco
Thank you Marco! This is so true.My error actually resided in a faulty memory allocation. =(Sorry about that.
ABeanSits
A: 

Can you help me with the reciprocal issue ? I have one strig (ex "35.234543". I want to convert it into a latitude.

How can I do this ? This drives me crazy !!!

Thanks Thomas

thomas
Thomas, try using something looking like this: NSNumberFormatter *format = [[NSNumberFormatter alloc] init]; [formet setNumberStyle:NSNumberFormatterDecimalStyle]; NSNumber *aNumber = [format numberFromString:@"35.234543"]; [format release];Good luck.
ABeanSits