Convert type CLLocationCoordinate2D to a number or string

I was wondering how to convert CLLocationCoordinate2D latitude and longitude values ​​to numbers or string values. Iver tried several different methods, but they do not work:

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 latitude is: %@", tmpLat);
NSLog("User longitude is: %@", tmpLong);

This returns a warning by the compiler.

Warning

warning: passing argument 1 of 'NSLog' from incompatible pointer type

How to do it?

Any help would be appreciated.

thank

+5
source share
1 answer

You did not mention what the warning is, but most likely because you forgot @before the NSLog lines:

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

Your updated code should be:

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

NSLog expects an NSString parameter that requires the @ sign before. Unsigned @ string is a simple C string, not an NSString object.

+7
source

All Articles