将Cocoa Touch纬度/经度转换为不带度数符号的字符串

Atm*_*tma 1 cocoa cocoa-touch latitude-longitude nsstring cllocation

我正在尝试将CLLocation纬度/经度转换为字符串.我可以使用以下代码成功完成此操作:

// extract latitude from CLLocation object and cast to string
NSString *latitude = [[NSString alloc] initWithFormat:@"%g°", location.coordinate.latitude];
Run Code Online (Sandbox Code Playgroud)

这给了我一个像34.10111º的值.我希望这个数字是一个没有º度符号的纯字符串.

我应该用不同的格式初始化字符串吗?

我尝试使用格式@"%d"启动,字符串完全出现在另一个数字上.

Jim*_*uls 19

您的格式字符串中有一个度数符号.删除它,你应该没事.

至于你的问题的另一部分,%d因为格式说明符需要一个整数,并且你给它一个浮点数.你的%g是正确的,%e或者是%f.