我有一个带有坐标的数组字典的plist(存储为字符串)。
我想从每个数组创建一个CLLocationCoordinate2D并为地图创建一个叠加层。
我做到了 -
NSString *thePath = [[NSBundle mainBundle] pathForResource:@"Roots" ofType:@"plist"];
NSDictionary *pointsDic = [[NSDictionary alloc] initWithContentsOfFile:thePath];
NSArray *pointsArray = [NSArray arrayWithArray:[pointsDic objectForKey:@"roade1"]];
CLLocationCoordinate2D pointsToUse[256];
for(int i = 0; i < 256; i++) {
CGPoint p = CGPointFromString([pointsArray objectAtIndex:i]);
pointsToUse[i] = CLLocationCoordinate2DMake(p.x,p.y);
NSLog(@"coord %f",pointsToUse [i].longitude);
NSLog(@"coord %f",pointsToUse [i].latitude);
}
MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:pointsToUse count:256];
[[self mv] addOverlay:myPolyline];
但应用程序崩溃没有任何错误。 (顺便说一句,当我删除addOverLay方法时,应用程序不会崩溃)。
我有两个问题 -
我试图将pointsArray计数设置为CLLocationCoordinate2D的参数,就像那样 -
CLLocationCoordinate2D pointsToUse [pointsArray count];
我收到了一个错误。 如何动态设置CLLocationCoordinate2D?
感谢您的帮助。 沙尼
答案 0 :(得分:5)
O.K 问题确实存在于viewForOverlay方法中(感谢aBitObvious和其他所有方法)。 看来,阵列中点的线加载效果很好。
对于第二个问题,我将其分为两步:
NSInteger c = [pointsArray count];
CLLocationCoordinate2D pointsToUse[c];
并且它工作正常,所以如果有人想要从plist加载叠加层,那么这种方式对我有效。
由于 SHANI