【发布时间】: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