将 CLLocationCooperative2D 类型转换为数字或字符串
我想知道如何将 CLLocationCooperative2D 的纬度和经度值转换为数字或字符串值。 Iver 尝试了几种不同的方法,但它们不起作用:
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
我该怎么做?
任何帮助将不胜感激。
谢谢
I was wondering how to convert latitude and longitude values of CLLocationCoordinate2D to numbers or string values.
Iver tried a few different ways but they arene't working:
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);
This returns a warning by the compiler.
The warning is
warning: passing argument 1 of 'NSLog' from incompatible pointer type
How do I do this?
Any help would be appreciated.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有提到警告是什么,但很可能是因为您忘记了 NSLog 字符串前面的
@
:您更新的代码应该是:
NSLog 需要一个 NSString 参数,前面需要一个 @ 符号。如果没有 @ 符号,该字符串是一个普通的 C 字符串,而不是一个 NSString 对象。
You haven't mentioned what the warning is but it's most likely because you forgot the
@
in front of the NSLog strings:Your updated code should be:
NSLog expects an NSString parameter which needs an @ sign in front. Without the @ sign, the string is a plain C string not an NSString object.