0

注釈 (homeMark) が mapView に表示されません。IB で viewController デリゲートを作成しました

デリゲートメソッドでなぜか if ([annotation isKindOfClass:[HomeMark class]]) {

失敗.....注釈は「ホームマーク」クラスの一部ではありません...

私は何を間違っていますか?

コード...

- (IBAction)clubHouse:(id)sender{
    MKCoordinateRegion region = { {0.0, 0.0 } , {0.0,0.0} };
    region.center.latitude = 55.305858;
    region.center.longitude = 12.386036;


    CLLocationCoordinate2D coord = {
        .latitude = region.center.latitude, 
        .longitude = region.span.longitudeDelta};

    HomeMark *homeMark = [[HomeMark alloc] 
                          initWithCoordinate:coord 
                          andMarkTitle:@"Klubhus" 
                          andMarkSubTitle:@"Stevns Cykel Motion"];

    [mapMyView addAnnotation:homeMark];

    [mapMyView setMapType:MKMapTypeStandard];
    [mapMyView setZoomEnabled:YES];
    [mapMyView setScrollEnabled:YES];
    region.span.longitudeDelta = 0.007f;
    region.span.latitudeDelta = 0.007f;
    [mapMyView setRegion:region animated:YES];
    //[mapMyView setDelegate:sender];    
    mapMyView.showsUserLocation = YES;

}

そしてViewForAnnotation。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

    static NSString *identifier = @"MyLocation";
    if ([annotation isKindOfClass:[HomeMark class]]) {

        MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
        if (annotationView == nil) {
            annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        }
        else {
            annotationView.annotation = annotation;
        }

        annotationView.enabled = YES;
        annotationView.canShowCallout = YES;

        return annotationView;
    }

    return nil; 
}
4

1 に答える 1

1

座標を正しく指定していないようで、注釈が期待する場所にありません。

これの代わりに:

CLLocationCoordinate2D coord = {
    .latitude = region.center.latitude, 
    .longitude = region.span.longitudeDelta};  // <-- span doesn't make sense

これを試して:

CLLocationCoordinate2D coord = {
    .latitude = region.center.latitude, 
    .longitude = region.center.longitude};  // <-- not span
于 2012-06-30T18:01:34.967 に答える