2012-06-30 39 views
0

我的註釋(homeMark)未顯示在mapView中。 我做了我的viewController代表在IBXcode 4.3.3 Mapview,註釋未顯示

出於某種原因,在委託方法 如果([註釋isKindOfClass:[HomeMark類]){

失敗.....註釋不是「部分Homemark「類...

我在做什麼錯?

代碼...

- (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; 
} 
+0

我還是不明白爲什麼人們投票下來,不說爲什麼?就是剛剛#1全巨魔? – Sirens

回答

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 
+0

非常感謝,我不敢相信我沒有看到這一個。 啓動「自動完成」並不總是一個好主意。 再次感謝: - D. –