从数组创建 CLLocationCooperative2D

发布于 2024-10-10 01:51:45 字数 1126 浏览 3 评论 0原文

我有一个 plist,其中包含带有坐标的数组字典(存储为字符串)。

我想从每个数组创建一个 CLLocationCooperative2D 并为地图创建一个覆盖层。

我这样做了 -

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 方法时,应用程序不会崩溃)。

我有两个问题 -

  1. 我做错了什么?
  2. 我尝试将点数组计数设置为 CLLocationCooperative2D 的参数,如下 -

    CLLocationCooperative2DpointsToUse[pointsArray count];

我收到一个错误。 如何动态设置 CLLocationCooperative2D ?

感谢您的任何帮助。 沙尼

I have a plist with dictionary of array's with coordinates (stored as strings).

I want to create a CLLocationCoordinate2D from every array and crate an overlay for the map.

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).

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 -

    CLLocationCoordinate2D pointsToUse[pointsArray count];

And i am getting an error.
How can i set the CLLocationCoordinate2D dynamically ?

Thanks for any help.
Shani

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想挽留 2024-10-17 01:51:45

好的
问题确实出在 viewForOverlay 方法中(感谢 aBitObvious 和其他所有方法)。
看来从数组中加载点的线效果很好。

对于第二个问题,我只是将其分为两个步骤:

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

它工作得很好,所以如果有人正在寻找一种从 plist 加载叠加层的方法,这种方法对我来说很有效。

谢谢
沙尼

O.K
The problem was indeed in the viewForOverlay method (thanks aBitObvious and all the rest).
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.

Thanks
shani

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文