converting a CLLocationCoordinate2D type to number or string
I was wondering how to convert latitude and longit开发者_如何学运维ude 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
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.
精彩评论