从CLLocationDegrees生成字符串,例如在NSLog或StringWithFormat中

ABe*_*its 10 iphone cocoa-touch objective-c nslog nsstring

你好Stacked-专家!

我的问题:如何从CLLocationDegrees值生成一个字符串?

尝试失败:

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];
Run Code Online (Sandbox Code Playgroud)

当我查看CLLocationDegrees的定义时,它清楚地表明这是一个双重的:

typedef double CLLocationDegrees;
Run Code Online (Sandbox Code Playgroud)

我在这里错过了什么?这让我发疯了...请帮忙拯救我的心灵!

在此先感谢您的问候.// Abeansits

Mar*_*rco 34

这些是正确的:

NSLog(@"Value: %f", currentLocation.coordinate.latitude); //Tried with all NSLog specifiers.
NSNumber *tmp = [[NSNumber alloc] initWithDouble:currentLocation.coordinate.latitude];
Run Code Online (Sandbox Code Playgroud)

这是错误的,因为coordinate.latitude不是nsstring可能期望的对象.

NSString *tmp = [[NSString alloc] initWithFormat:@"%@", currentLocation.coordinate.latitude];
Run Code Online (Sandbox Code Playgroud)

如果你想要一个NSString:

myString = [[NSNumber numberWithDouble:currentLocation.coordinate.latitude] stringValue];
Run Code Online (Sandbox Code Playgroud)

要么

NSString *tmp = [[NSString alloc] initWithFormat:@"%f", currentLocation.coordinate.latitude];
Run Code Online (Sandbox Code Playgroud)

马尔科

  • @Marco你能用快速代码翻译这个吗? (3认同)