5

我想知道如何将 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

我该怎么做呢?

任何帮助,将不胜感激。

谢谢

4

1 回答 1

7

您没有提到警告是什么,但很可能是因为您忘记了@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 对象。

于 2011-08-01T13:55:41.160 回答