converting a CLLocationCoordinate2D type to number or string
Asked Answered
P

1

5

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

Poinsettia answered 1/8, 2011 at 13:38 Comment(0)
U
7

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.

Unbalance answered 1/8, 2011 at 13:55 Comment(2)
Sorry Anna Karenina, about the confusion. I have updated information my question and added the warning. Please see above thanksPoinsettia
The problem is indeed that you do not have the @ sign in front of the NSLog strings.Unbalance

© 2022 - 2024 — McMap. All rights reserved.