【问题标题】:converting a CLLocationCoordinate2D type to number or string将 CLLocationCoordinate2D 类型转换为数字或字符串
【发布时间】:2011-08-01 13:38:13
【问题描述】:

我想知道如何将 CLLocationCoordinate2D 的纬度和经度值转换为数字或字符串值。 我尝试了几种不同的方法,但都不起作用:

CLLocationCoordinate2D centerCoord;
centerCoord.latitude = self.locModel.userLocation.coordinate.latitude ;
centerCoord.longitude = self.locModel.userLocation.coordinate.longitude; 
NSString *tmpLat = [[NSString alloc] initWithFormat:@"%g", centerCoord.latitude];
NSString *tmpLong = [[NSString alloc] initWithFormat:@"%g", centerCoord.longitude];

NSLog("User's latitude is: %@", tmpLat);
NSLog("User's longitude is: %@", tmpLong);

这会返回编译器的警告。

警告是

warning: passing argument 1 of 'NSLog' from incompatible pointer type

我该怎么做?

任何帮助将不胜感激。

谢谢

【问题讨论】:

    标签: cocoa cllocation


    【解决方案1】:

    您没有提到警告是什么,但很可能是因为您忘记了 NSLog 字符串前面的 @

    NSLog(@"User's latitude is: %f", self.locModel.userLocation.coordinate.latitude );
    NSLog(@"User's longitude is: %f", self.locModel.userLocation.coordinate.longitude );
    

    您更新后的代码应该是:

    NSLog(@"User's latitude is: %@", tmpLat);
    NSLog(@"User's longitude is: %@", tmpLong);
    

    NSLog 需要一个 NSString 参数,它前面需要一个 @ 符号。如果没有 @ 符号,则字符串是纯 C 字符串而不是 NSString 对象。

    【讨论】:

    • 对不起安娜卡列尼娜,关于混乱。我已经更新了我的问题的信息并添加了警告。请看上面谢谢
    • 问题确实是你的NSLog字符串前面没有@符号。
    猜你喜欢
    • 1970-01-01
    • 2015-04-09
    • 1970-01-01
    • 2015-08-28
    • 1970-01-01
    • 1970-01-01
    • 2018-08-16
    • 1970-01-01
    相关资源
    最近更新 更多