For the past 2 hours, I have been struggling with implementing a CLGeocoder
class method that is used for reverse geocoding a location.
The code that is provided for this method in the Xcode
documentation under the CLGeocode
class reference is this:
- (void)reverseGeocodeLocation:(CLLocation *)location completionHandler:(CLGeocodeCompletionHandler)completionHandler
I was trying to use that in my code and wasn't having any luck. So I looked over some old stackoverflow questions and found an implementation that ended up working for me.
This is the code that works for me:
-(IBAction)gpsButton {
CLGeocoder *geocoder = [[CLGeocoder alloc]init];
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error){
CLPlacemark *placemark = placemarks[0];
NSLog(@"Found %@", placemark.thoroughfare);
}
];
}
What I don't understand is why the xcode documentation includes (CLLocation *) and (CLGeocodeCompletionHandler) when that's not really how the final code needs to look.
Is it just trying to remind me that the "location" object should be an instance of the CLLocation class and that the "completionHandler" object should be an instance of the CLGeocodeCompletionHandler class?
Is it trying to remind me that before implementing this method I need to create and initialize objects for the CLLocation
class and CLGeocodeCompletionHandler
class so the method can function properly? And if this is the case then why does CLLocation
have a pointer in the xcode example but CLGeocodeCompletionHandler
does not?
I realize that this is a "fundamentals" type question but I have gone over several of my go-to references and the way they are explaining things are really not helping me with this current confusion.
Thank you for the help.