[英]create CLLocationCoordinate2D from array
我有一个带有坐标的数组字典的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?
谢谢你的帮助。 沙尼
好问题确实存在于viewForOverlay方法中(感谢aBitObvious和其他所有方法)。 看起来阵列中点的线加载效果很好。
对于第二个问题,我把它分成两步:
NSInteger c = [pointsArray count];
CLLocationCoordinate2D pointsToUse[c];
并且它工作正常,所以如果任何人正在寻找从plist加载叠加层的方法,那么这种方式对我有用。
谢谢shani
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.