从数组创建CLLocationCoordinate2D

sha*_*oga 6 iphone mapkit

我有一个带有坐标的数组字典的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];
Run Code Online (Sandbox Code Playgroud)

但应用程序崩溃没有任何错误.(顺便说一句,当我删除addOverLay方法时,应用程序不会崩溃).

我有两个问题 -

  1. 我究竟做错了什么?
  2. 我试图将pointsArray计数设置为CLLocationCoordinate2D的参数,如下所示 -

    CLLocationCoordinate2D pointsToUse [pointsArray count];

我收到了一个错误.如何动态设置CLLocationCoordinate2D?

谢谢你的帮助.沙尼

sha*_*oga 5

好问题确实存在于viewForOverlay方法中(感谢aBitObvious和其他所有方法).看起来阵列中点的线加载效果很好.

对于第二个问题,我把它分成两步:

  NSInteger c = [pointsArray count];
    CLLocationCoordinate2D pointsToUse[c];
Run Code Online (Sandbox Code Playgroud)

并且它工作正常,所以如果任何人正在寻找从plist加载叠加层的方法,那么这种方式对我有用.

谢谢shani