尝试构建谷歌地图路径时崩溃

时间:2012-06-29 14:11:29

标签: iphone ios google-maps

我有一个相当紧急的问题,我找不到答案。 我试图在iPhone应用程序中使用谷歌地图API绘制当前位置和目的地之间的路径。我从Google获取数据,解析JSON没有错误,解码折线然后我有这个方法:

-(void) loadRouteWithPoints:(NSArray *) routes
{
    CLLocationCoordinate2D coords[[routes count]];
    for(int i = 0; i < routes.count; i++)
    {
        CLLocation* loc = (CLLocation*)[NSKeyedUnarchiver unarchiveObjectWithData:[routes objectAtIndex:i]];
        CLLocationCoordinate2D c;
        c.latitude  = loc.coordinate.latitude;
        c.longitude = loc.coordinate.longitude;
        coords[i]   = c;
    }

    MKPolyline *line = [MKPolyline polylineWithCoordinates:(CLLocationCoordinate2D*)coords count:[routes count]];
    [self.mapsView addOverlay:line];    
}

这会在[NSKeyedUnarchiver unarchiveObjectWithData:[routes objectAtIndex:i]];上引发一个例外:

  

“ - [CLLocation bytes]:无法识别的选择器发送到实例”

我作为参数发送的数组是解码折线后得到的数据,它不是nil,在我的测试中它有47个值。我可以看到它们,每个条目都是这样的:

  

1 + 44.47874069,+ 26.10523033&GT; +/- 0.00m(速度-1.00 mps / course -1.00)@ 6/29/12 17:09:37东欧夏季时间

您是否知道可能导致此次崩溃的原因以及如何修复?

1 个答案:

答案 0 :(得分:0)

此处的错误表示您认为[routes objectAtIndex:x]中的值可能不是您认为的值。

尝试分离出这一行,看看在[routes objectAtIndex:x]中检索到的对象究竟是什么类,你可能会得到你的答案。

该对象似乎已经是一个CLLocation而且不​​需要取消编码......