gpt4 book ai didi

iphone - 从 CLLocationDegrees 生成一个字符串,例如在 NSLog 或 StringWithFormat 中

转载 作者:太空狗 更新时间:2023-10-30 03:24:50 26 4
gpt4 key购买 nike

您好 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];

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

typedef double CLLocationDegrees;

我在这里错过了什么?这让我发疯了......请帮我挽救一下!

提前致谢并致以最诚挚的问候。//放弃

最佳答案

这些是正确的:

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

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

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

如果你想要一个 NSString:

myString = [[NSNumber numberWithDouble:currentLocation.coordinate.latitude] stringValue];

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

马可

关于iphone - 从 CLLocationDegrees 生成一个字符串,例如在 NSLog 或 StringWithFormat 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1329008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com