converting a CLLocationCoordinate2D type to number or string

风格不统一 提交于 2019-12-12 08:13:35

问题


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


回答1:


You haven't mentioned what the warning is but it's most likely because you forgot the @ in front of the NSLog strings:

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

Your updated code should be:

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

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.



来源:https://stackoverflow.com/questions/6899232/converting-a-cllocationcoordinate2d-type-to-number-or-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!