首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从数组创建CLLocationCoordinate2D

从数组创建CLLocationCoordinate2D
EN

Stack Overflow用户
提问于 2011-01-04 23:17:47
回答 1查看 5.5K关注 0票数 6

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

我想从每个数组创建一个CLLocationCoordinate2D,并为地图设置一个覆盖层。

我这么做了-

代码语言:javascript
复制
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. ,我试着把pointsArray计数设为CLLocationCoordinate2D的论点,就像这样-

CLLocationCoordinate2D pointsToUsepointsArray count;

我有个错误。如何动态设置CLLocationCoordinate2D?

谢谢你的帮助。沙尼

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-05 06:51:34

好的,问题确实出现在viewForOverlay方法中(谢谢aBitObvious和其他方法)。从数组中加载点的线条看起来很好。

关于第二个问题,我把它分成了两个步骤:

代码语言:javascript
复制
  NSInteger c = [pointsArray count];
    CLLocationCoordinate2D pointsToUse[c];

而且它工作得很好,所以如果有人在寻找一种方法从plist加载覆盖层,那么这种方式对我来说是可行的。

谢了沙尼

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4599443

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档