简体   繁体   English

从数组创建CLLocationCoordinate2D

[英]create CLLocationCoordinate2D from array

I have a plist with dictionary of array's with coordinates (stored as strings). 我有一个带有坐标的数组字典的plist(存储为字符串)。

I want to create a CLLocationCoordinate2D from every array and crate an overlay for the map. 我想从每个数组创建一个CLLocationCoordinate2D并为地图创建一个叠加层。

I did that - 我做到了 -

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];

but the app is crashing without any error. 但应用程序崩溃没有任何错误。 (BTW when i remove the addOverLay method the app does not crash). (顺便说一句,当我删除addOverLay方法时,应用程序不会崩溃)。

I have 2 questions- 我有两个问题 -

  1. What am i doing wrong? 我究竟做错了什么?
  2. I have tried to set the pointsArray count as the argument for the CLLocationCoordinate2D like that - 我试图将pointsArray计数设置为CLLocationCoordinate2D的参数,如下所示 -

    CLLocationCoordinate2D pointsToUse[pointsArray count]; CLLocationCoordinate2D pointsToUse [pointsArray count];

And i am getting an error. 我收到了一个错误。 How can i set the CLLocationCoordinate2D dynamically ? 如何动态设置CLLocationCoordinate2D?

Thanks for any help. 谢谢你的帮助。 Shani 沙尼

OK The problem was indeed in the viewForOverlay method (thanks aBitObvious and all the rest). 好问题确实存在于viewForOverlay方法中(感谢aBitObvious和其他所有方法)。 It appears that the line loading of the point from the array is working good. 看起来阵列中点的线加载效果很好。

and for the second question i just separated it to 2 steps: 对于第二个问题,我把它分成两步:

  NSInteger c = [pointsArray count];
    CLLocationCoordinate2D pointsToUse[c];

and it worked fine, so if any one is looking for a way to load overlayes from plist, that way is working for me. 并且它工作正常,所以如果任何人正在寻找从plist加载叠加层的方法,那么这种方式对我有用。

Thanks shani 谢谢shani

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM