Ios MKCoordinateRegionMakeWithDistance-throws“;线程1:信号SIGABRT“;

Ios MKCoordinateRegionMakeWithDistance-throws“;线程1:信号SIGABRT“;,ios,ios6,mkmapview,mapkit,Ios,Ios6,Mkmapview,Mapkit,我有一个新的问题,我不知道为什么。。。我的进一步解决方案由Rob发布。我喜欢他的工作,在iOS 6.1升级之前,他的工作非常出色 - (void)loadKml:(NSURL *)url { // parse the kml Parser *parser = [[Parser alloc] initWithContentsOfURL:url]; parser.rowElementName = @"Placemark"; parser.elementNames =

我有一个新的问题,我不知道为什么。。。我的进一步解决方案由Rob发布。我喜欢他的工作,在iOS 6.1升级之前,他的工作非常出色

- (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];
}
有几点想法:

  • 您是否已检查以确保您的
    IBOutlet
    mapView
    已连接?如果
    self.mapView
    nil
    ,应用程序可能会崩溃

  • 您是否查看了
    注释。协调
    以确保获得有效的结果?可能有一个
    MKUserLocation
    还没有有效值

  • 我知道是我给你安排的,但我注意到我们没有检查没有地点的情况。您可能需要以下内容:

    if ([self.mapView.annotations count] > 0)
    {
        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);
        }
        [self.mapView setRegion:region animated:YES];
    }
    
    正在检索您的图像URL吗?我认为这应该是:

    parser.attributeNames = @[@"src"];
    
    也许您对解析器做了一些更改,但是
    didStartElement
    attributeDict
    将永远不会有一个对象由
    img src=
    设置关键字。如果XML标记是
    ,那么您要查找的属性名称就是
    src

  • 有几点想法:

  • 您是否已检查以确保您的
    IBOutlet
    mapView
    已连接?如果
    self.mapView
    nil
    ,应用程序可能会崩溃

  • 您是否查看了
    注释。协调
    以确保获得有效的结果?可能有一个
    MKUserLocation
    还没有有效值

  • 我知道是我给你安排的,但我注意到我们没有检查没有地点的情况。您可能需要以下内容:

    if ([self.mapView.annotations count] > 0)
    {
        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);
        }
        [self.mapView setRegion:region animated:YES];
    }
    
    正在检索您的图像URL吗?我认为这应该是:

    parser.attributeNames = @[@"src"];
    
    也许您对解析器做了一些更改,但是
    didStartElement
    attributeDict
    将永远不会有一个对象由
    img src=
    设置关键字。如果XML标记是
    ,那么您要查找的属性名称就是
    src


  • 你有没有检查过,在那一点上你实际上有一个注释要使用?可能您的
    self.mapView.annotations[0]
    返回的值为零。

    您是否检查过您当时是否有要使用的注释?也许你的
    self.mapView.annotations[0]
    返回了零。

    1。)是的,钩住了2。)我不知道如何测试它3。)我尝试了代码,我的应用程序将运行没有错误,但有一个空映射4。)更正:-)@curtismoschmidt 2。将NSLog语句放在给出异常的行之前。或者更好的方法是在代码中设置一个断点并单步执行该代码。(请参阅)当您遇到这样的异常时,总是因为某个无效变量被传递给某个方法/函数。我用注释标记的代码行,请参阅:
    region=mkcoordinaeregionmakewithdistance(annotation.coordinate,100.0,100.0)如果我做了
    NSLog(@“%@”,annotation.coordinate)在这行前后,我将得到一个警告:
    格式指定类型“id”,但参数的类型是CCLocationCoordinate2D
    我有点confused@CurtisTimoSchmidt是的,所以你可以做
    NSLog(@“%@:%f,%f”,注解,注解。坐标。纬度,注解。坐标。经度)1。)是挂接2。)我不知道如何测试它3。)我尝试了代码,我的应用程序将运行没有错误,但有一个空映射4。)更正:-)@curtismoschmidt 2。将NSLog语句放在给出异常的行之前。或者更好的方法是在代码中设置一个断点并单步执行该代码。(请参阅)当您遇到这样的异常时,总是因为某个无效变量被传递给某个方法/函数。我用注释标记的代码行,请参阅:
    region=mkcoordinaeregionmakewithdistance(annotation.coordinate,100.0,100.0)如果我做了
    NSLog(@“%@”,annotation.coordinate)在这行前后,我将得到一个警告:
    格式指定类型“id”,但参数的类型是CCLocationCoordinate2D
    我有点confused@CurtisTimoSchmidt是的,所以你可以做
    NSLog(@“%@:%f,%f”,注解,注解。坐标。纬度,注解。坐标。经度)