I am actually using core location along with map kit framework to get the user location on a button's click. I have two view controllers. The first one is a normal view controller with the map view and all the core location processes done in it along with reverse geo coding. The second one is a table view controller that displays the obtained data from geo coding and location's latitude and longitude.
The problem which I get is that I am not able to pass the information of the current location to the next view. But, I can pass my geo coding values. It seems strange for me and any help would be much appreciated.
mapViewController.m
#import "mapViewController.h"
@interface mapViewController ()
{
CLLocationManager *locationManager;
CLGeocoder *geoCoder;
CLPlacemark *placemark;
addressViewController *view;
}
@end
@implementation mapViewController
@synthesize mapView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
locationManager = [[CLLocationManager alloc]init];
geoCoder = [[CLGeocoder alloc]init];
self.addressOutlet.enabled = NO;
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"addressSegue"])
{
view= segue.destinationViewController;
// assigning the addressPlacemark the same value as the current placemark
view.addressPlacemark = placemark;
NSLog(@"this is perfectly executed");
}
}
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 600, 600);
[self.mapView setRegion:region animated:YES];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *newOne = [locations lastObject];
[locationManager stopUpdatingLocation];
NSLog(@"the new location is : %@", newOne);
NSLog(@"the latitude is %f", newOne.coordinate.latitude);
NSLog(@"the speed is %.2f mps", newOne.speed);
NSLog(@"at time : %@",newOne.timestamp);
//These 4 NSLog statements are returning the outputs as expected
[geoCoder reverseGeocodeLocation:newOne completionHandler:^(NSArray *placemarks, NSError *error) {
placemark = [placemarks objectAtIndex:0];
NSLog(@"the current city is %@",placemark.locality);
self.addressOutlet.enabled = YES;
// view.currentLocation = [[CLLocation alloc]init];
view.currentLocation = newOne; // assigning currentLocation the same location as the newOne
NSLog(@"the currentLocation object has the location : \n %@",view.currentLocation);
//problem : the output of this NSLog gives Null
}];
}