how can i save latitude and longitude coordinates to a nsstring so that i can use it in another function. basically, i just want to show the values retrieved from the coordinates to be passed to a uilabel.
- (void)viewDidLoad
{
[super viewDidLoad];
[self getCurrentLocation];
NSLog(@"lat is %@ : lon is %@",self.latPoint, self.longPoint);
}
i tried to retrieve the above with a NSlog and it shows as null. i have two NSString properties created in my .h file as latPoint/longPoint
- (void)getCurrentLocation {
if ([CLLocationManager locationServicesEnabled]) {
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
} else {
NSLog(@"Location services are not enabled");
}
}
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *location = [locations lastObject];
self.latPoint = [NSString stringWithFormat:@"%f", location.coordinate.latitude];
self.lonPoint = [NSString stringWithFormat:@"%f", location.coordinate.longitude];
}