I am trying to get a CLLocationCoordinate2D from a CLLocation object. I am using the following code, which is called through an NSNotification:
-(void)setMapCenterWith:(CLLocation*)location {
CLLocationCoordinate2D coord = location.coordinate;
[self moveToCoordinate:coord];
}
I have verified that the location object being passed in is valid and contains a location. However, when the line containing location.coordinate
is called, the app crashes with the following error:
[NSConcreteNotification coordinate]: unrecognized selector sent to instance
Here is the log output on the location object:
NSConcreteNotification 0x798988e0 {name = PPTFormSubmittedWithLocation; object = <+38.05230000,-81.10880000> +/- 5.00m (speed -1.00 mps / course -1.00) @ 3/22/15, 12:35:34 PM Eastern Daylight Time}
Any idea why this is happneing? Thanks!
setMapCenterWith
is called by an NSNotificationCenter
, which means it needs to take an NSNotification
as it's parameter:
-(void)setMapCenterWith:(NSNotification *)notif
It looks like the notification's object is the CLLocation
you are interested in, so you need to change your method to this:
-(void)setMapCenterWith:(NSNotification *)notif {
CLLocation *location = notif.object;
CLLocationCoordinate2D coord = location.coordinate;
[self moveToCoordinate:coord];
}