I’m trying to determine the iPhone user’s location using a CLLocationManager and CLGeocoder.
My CLLocationManager seems to work well, but unfortunately the CLGeocoder doesn’t do what I would like it to do.
Some code excerpts:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
[self.locationManager stopUpdatingLocation];
NSLog(@"Location updated to: %@",newLocation);
[self.geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"Reverse geocoding finished");
self.currentPlacemark = [placemarks objectAtIndex:0];
NSLog(@"%@",self.currentPlacemark.locality);
NSLog(@"%@",self.currentPlacemark.ISOcountryCode);
}];
}
- (void)getCurrentLocation {
NSLog(@"Determining current location");
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager startUpdatingLocation];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self getCurrentLocation];
}
self.currentPlacemark is a CLPlacemark object.
self.geocoder is a CLGeocoder object.
self.locationManager is a CLLocationManager object.
What am I missing? Why isn’t this working?
I honestly spent hours and I’m slowly starting to become desperate …
Yes, you should alloc and init your geocoder.