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



我有一个相当紧迫的问题,我找不到答案。我正在尝试在iPhone应用程序中使用谷歌地图API绘制当前位置和目的地之间的路径。我正在从谷歌获取数据,解析 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 个值。我可以看到它们,每个条目如下所示:

<+44.47874069,+26.10523033> +/- 0.00m (速度 -1.00 mps/路线 -1.00) @ 12-6-29 17:09:37 东欧夏令时

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

这里的错误表明你认为在[routes objectAtIndex:x]中的值可能不是你认为的那样。

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

似乎该对象已经是 CLLocation 并且不需要未编码......

相关内容

最新更新