0

我想在地图上绘制一条路线,从 csv 文件中获取坐标。我构建了两个示例代码(来自 The Reluctant Blogger),它们在原始 csv 文件上运行良好,但是当我使用转换后的 gpx 文件到 csv 时(使用 GPSBabelFE),应用程序崩溃并出现以下错误:

2013-06-21 02:46:10.606 os4Maps[10178:907] * 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[__NSArrayI objectAtIndex:]:索引 1 超出范围 [0 .. 0]” * First throw call stack: (0x31bbb3e7 0x398b6963 0x31b0621d 0x484af 0x48151 0x339e9579 0x47e81 0x33a2aaa1 0x33a2a625 0x33a22833 0x339cad1f 0x339ca7ad 0x339ca1ef 0x356e25f7 0x356e2227 0x31b903e7 0x31b9038b 0x31b8f20f 0x31b0223d 0x31b020c9 0x33a2146d 0x33a1e2b9 0x47dfd 0x39ce3b20) libc++abi.dylib: terminate called throwing an exception (lldb)

有谁知道为什么会这样?

我检查了文件,它不是空的,在我看来,没问题。

最新样本来自这里,修改后的 csv 文件来自这里

谢谢!

4

1 回答 1

0

在您的代码中的哪一点发生这种情况?您是否尝试设置断点?

从链接的代码中,您objectAtIndex:在 for 循环中出现了 3 次。第一个应该没问题,但您可能想要断言[latLonArr count] == 2

NSArray* latLonArr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@","]];

assert([latLonArr count] == 2);

CLLocationDegrees latitude = [[latLonArr objectAtIndex:0] doubleValue];
CLLocationDegrees longitude = [[latLonArr objectAtIndex:1] doubleValue];
于 2013-06-21T07:11:36.970 回答