从Cllocation获取CLLocationCorrdinate2D时出错

时间:2015-03-22 16:33:34

标签: ios objective-c cllocationmanager 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}

知道为什么这是幸福的吗?谢谢!

1 个答案:

答案 0 :(得分:1)

{p> setMapCenterWithNSNotificationCenter调用,这意味着需要NSNotification作为参数:

-(void)setMapCenterWith:(NSNotification *)notif

看起来通知的对象是您感兴趣的CLLocation,因此您需要将方法更改为:

-(void)setMapCenterWith:(NSNotification *)notif {
    CLLocation *location = notif.object;
    CLLocationCoordinate2D coord = location.coordinate;
    [self moveToCoordinate:coord];
}