【问题标题】:Crash while trying to build google maps path尝试构建谷歌地图路径时崩溃
【发布时间】:2012-06-29 14:11:28
【问题描述】:

我有一个相当紧迫的问题,我找不到答案。 我正在尝试在 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 个值。我可以看到它们,每个条目看起来像这样:

+/- 0.00m(速度 -1.00 mps / 航向 -1.00)@ 2012 年 6 月 29 日 17:09:37 东欧夏令时

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

【问题讨论】:

  • 您在发布的内容中有您的答案。异常告诉你问题是什么。
  • 我知道 CLLocation 没有像“字节”这样的方法/属性。我的问题是如何解决这个问题。显然,它对其他人有用。所以也许 SDK 发生了一些变化。

标签: iphone ios google-maps


【解决方案1】:

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

尝试分隔线,查看在 [routes objectAtIndex:x] 检索到的对象的确切类类型,您可能会得到答案。

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

【讨论】:

  • 我正在打印该值,它似乎没问题。所有的值都和上面贴的一样——当然,坐标不同。如果我不打电话给unarchiveObjectWithData 它可以工作,但找到的路径不正确。它有转弯,有点像街道,但不完全。路径的某些部分穿过公园和湖泊,没有沿着街道。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多