首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MKCoordinateRegionMakeWithDistance抛出“线程1:信号信号”

MKCoordinateRegionMakeWithDistance抛出“线程1:信号信号”
EN

Stack Overflow用户
提问于 2013-03-20 00:48:39
回答 2查看 772关注 0票数 1

我有一个新的问题,我不知道为什么.我的另一个解决方案是Rob发布的here。我喜欢他的工作,在iOS 6.1更新之前,它工作得很好。

代码语言:javascript
复制
- (void)loadKml:(NSURL *)url
{
    // parse the kml

    Parser *parser = [[Parser alloc] initWithContentsOfURL:url];
    parser.rowElementName = @"Placemark";
    parser.elementNames = @[@"name", @"Snippet", @"coordinates", @"description"];
    parser.attributeNames = @[@"img src="];
    [parser parse];

    // add annotations for each of the entries

    for (NSDictionary *locationDetails in parser.items)
    {
        MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
        annotation.title = locationDetails[@"name"];
        annotation.subtitle = locationDetails[@"Snippet"];
        NSArray *coordinates = [locationDetails[@"coordinates"] componentsSeparatedByString:@","];
        annotation.coordinate = CLLocationCoordinate2DMake([coordinates[1] floatValue], [coordinates[0] floatValue]);
        [self.mapView addAnnotation:annotation];
    }

    // update the map to focus on the region that encompasses all of your annotations

    MKCoordinateRegion region;
    if ([self.mapView.annotations count] > 1)
    {
        region = [self regionForAnnotations:self.mapView.annotations];
        region = MKCoordinateRegionMake(region.center, MKCoordinateSpanMake(region.span.latitudeDelta * 1.05, region.span.longitudeDelta * 1.05));  // expand the region by 5%
    }
    else
    {
        id<MKAnnotation> annotation = self.mapView.annotations[0];
        region = MKCoordinateRegionMakeWithDistance(annotation.coordinate, 100.0, 100.0); // >>>this line throws: "Thread 1: signal SIGABRT"<<<
    }
    [self.mapView setRegion:region animated:YES];
}

自从更新到iOS 6.1模拟器后,它就不工作了。

编辑:我得到这个错误:

代码语言:javascript
复制
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-20 01:43:18

我有几个想法:

  1. 您是否检查过mapViewIBOutlet是否已连接?如果self.mapViewnil,应用程序可能会崩溃。
  2. 你有没有看过annotation.coordinate,以确保得到的结果是有效的?也许有一个MKUserLocation还没有有效的值,我知道我是那个给你们这个例程的人,但是我注意到我们没有检查没有位置的情况。你可能想要这样的东西:

if ( annotation count > 0) {annotation region;if (annotation count > 1) { region = self regionForAnnotations:self.mapView.annotations;region = MKCoordinateRegionMake(region.center,MKCoordinateSpanMake(region.span.latitudeDelta * 1.05,region.center* 1.05));//将区域扩展5%Else{ id self.mapView.annotations= self.mapView.annotations;region = MKCoordinateRegionMakeWithDistance(annotation.coordinate,100.0,100.0);} self.mapView设置region:region动画:是;}

  • 顺便说一句,我注意到您正在使用:

parser.attributeNames = @@"img src=";

这是在检索您的图像URL吗?我本以为这应该是:

parser.attributeNames =@@“源”;

也许您已经对解析器做了一些更改,但是didStartElementattributeDict永远不会有一个以img src=为键的对象。如果XML标记是<img src="http://blah.blah.blah/0.jpg">,那么您要查找的属性名称就是src.

票数 1
EN

Stack Overflow用户

发布于 2013-03-20 07:02:27

你有没有检查过在这一点上你实际上有一个注解要使用?也许你的self.mapView.annotations[0]返回了nil。

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

https://stackoverflow.com/questions/15505573

复制
相关文章

相似问题

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