Cocoa 将CLLocationCoordinate2D类型转换为数字或字符串
我想知道如何将CLLocationCoordinate2D的纬度和经度值转换为数字或字符串值。 Iver尝试了几种不同的方法,但都不起作用:Cocoa 将CLLocationCoordinate2D类型转换为数字或字符串,cocoa,cllocation,Cocoa,Cllocation,我想知道如何将CLLocationCoordinate2D的纬度和经度值转换为数字或字符串值。 Iver尝试了几种不同的方法,但都不起作用: CLLocationCoordinate2D centerCoord; centerCoord.latitude = self.locModel.userLocation.coordinate.latitude ; centerCoord.longitude = self.locModel.userLocation.coordinate.longitude
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
我该怎么做
任何帮助都将不胜感激
谢谢您没有提到警告是什么,但很可能是因为您忘记了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对象。安娜·卡列尼娜(Anna Karenina)对此感到困惑,很抱歉。我已经更新了我的问题信息并添加了警告。请参见上文,谢谢。问题确实在于NSLog字符串前面没有@符号。