0

下面的代码用于进行搜索MKLocalSearch并将结果加载到数组中。

这个数组被传递给我的[self.mapView addAnnotations:annotations]方法。一切都很好,直到我尝试viewcontroller通过点击后退按钮(在我的故事板导航栏中)来消除它。

我明白了EXC_BAD_ACCESS(code=1, address=0x4)。如果我注释掉下面的 Show Pins 部分,问题就会消失(当然我现在没有加载我的注释)。

请帮忙!

-(void)issueLocalSearchLookup:(NSString *)searchString usingPlacemarksArray:(NSArray *)placemarks {


self.coords =  mapView.userLocation.coordinate;


// Set the size of the region we want to get search results for.
MKCoordinateSpan span = MKCoordinateSpanMake(0.001250, 0.001250);
MKCoordinateRegion region = MKCoordinateRegionMake(mapView.userLocation.coordinate, span);   

[self.mapView setRegion:region animated:YES];



// Create the search request
self.localSearchRequest = [[MKLocalSearchRequest alloc] init];
self.localSearchRequest.region = region;
self.localSearchRequest.naturalLanguageQuery = searchString;

// Perform the search request...
self.localSearch = [[MKLocalSearch alloc] initWithRequest:self.localSearchRequest];
[self.localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error) {

    if(error){

        NSLog(@"localSearch startWithCompletionHandlerFailed!  Error: %@", error);
        return;

    } else {

        // We are here because we have data!

        for(MKMapItem *mapItem in response.mapItems){

            // Show pins...

            NSMutableArray *annotations = [NSMutableArray array];


            Annotation *annotation = [[Annotation alloc] initWithCoordinate: mapItem.placemark.location.coordinate];
            annotation.title = mapItem.name;
            annotation.subtitle = mapItem.placemark.addressDictionary[(NSString *)kABPersonAddressStreetKey];
            [mapView addAnnotation:annotation];
            NSLog(@"Name for result: = %@", mapItem.name);

              [self.mapView addAnnotations:annotations];

                NSLog(@"Name for result: = %@", mapItem.name);


        }

        MKCoordinateSpan span = MKCoordinateSpanMake(0.01, 0.01);
        MKCoordinateRegion region = MKCoordinateRegionMake(self.coords, span);
        [self.mapView setRegion:region animated:YES];


    }
}];


         }  
4

1 回答 1

0

我已经将我的自定义注释设置为 NKPlacemark 的子类......我需要让它成为 NSObject 的子类。

于 2013-05-15T17:15:46.417 回答