2012-06-30 37 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. –