从 Cllocation 获取 CLLocationCorrdinate2D 时出错
Error getting CLLocationCorrdinate2D from Cllocation
我正在尝试从 CLLocation 对象获取 CLLocationCoordinate2D。我正在使用以下代码,它通过 NSNotification 调用:
-(void)setMapCenterWith:(CLLocation*)location {
CLLocationCoordinate2D coord = location.coordinate;
[self moveToCoordinate:coord];
}
我已验证传入的位置对象有效且包含位置。但是,当调用包含 location.coordinate
的行时,应用程序崩溃并出现以下错误:
[NSConcreteNotification coordinate]: unrecognized selector sent to instance
这是位置对象上的日志输出:
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}
知道为什么会这样吗?谢谢!
setMapCenterWith
由 NSNotificationCenter
调用,这意味着它需要将 NSNotification
作为参数:
-(void)setMapCenterWith:(NSNotification *)notif
看起来通知的对象是您感兴趣的CLLocation
,因此您需要将方法更改为:
-(void)setMapCenterWith:(NSNotification *)notif {
CLLocation *location = notif.object;
CLLocationCoordinate2D coord = location.coordinate;
[self moveToCoordinate:coord];
}
我正在尝试从 CLLocation 对象获取 CLLocationCoordinate2D。我正在使用以下代码,它通过 NSNotification 调用:
-(void)setMapCenterWith:(CLLocation*)location {
CLLocationCoordinate2D coord = location.coordinate;
[self moveToCoordinate:coord];
}
我已验证传入的位置对象有效且包含位置。但是,当调用包含 location.coordinate
的行时,应用程序崩溃并出现以下错误:
[NSConcreteNotification coordinate]: unrecognized selector sent to instance
这是位置对象上的日志输出:
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}
知道为什么会这样吗?谢谢!
setMapCenterWith
由 NSNotificationCenter
调用,这意味着它需要将 NSNotification
作为参数:
-(void)setMapCenterWith:(NSNotification *)notif
看起来通知的对象是您感兴趣的CLLocation
,因此您需要将方法更改为:
-(void)setMapCenterWith:(NSNotification *)notif {
CLLocation *location = notif.object;
CLLocationCoordinate2D coord = location.coordinate;
[self moveToCoordinate:coord];
}