我有一个带有坐标的数组字典(存储为字符串)的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方法时,应用程序不会崩溃)。
我有两个问题-
CLLocationCoordinate2D pointsToUsepointsArray count;
我有个错误。如何动态设置CLLocationCoordinate2D?
谢谢你的帮助。沙尼
发布于 2011-01-05 06:51:34
好的,问题确实出现在viewForOverlay方法中(谢谢aBitObvious和其他方法)。从数组中加载点的线条看起来很好。
关于第二个问题,我把它分成了两个步骤:
NSInteger c = [pointsArray count];
CLLocationCoordinate2D pointsToUse[c];而且它工作得很好,所以如果有人在寻找一种方法从plist加载覆盖层,那么这种方式对我来说是可行的。
谢了沙尼
https://stackoverflow.com/questions/4599443
复制相似问题