地图搞乱中的多个注释

时间:2013-05-28 10:20:49

标签: iphone ios map

enter image description here我在地图中有一个点作为引脚注释并显示自定义注释视图。我的问题是,当我点击点有时点后面自定义注释视图来自自定义注释视图而不是显示在它后面

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{ 
    MKAnnotationView *annotationView;
    PinAnnotationView *pinView = nil;
    NSString *identifier;
    if ([annotation isKindOfClass:[DisplayMap class]]) 
    {
        identifier = @"Pin";
        NSInteger myid = ((DisplayMap *)annotation).takeid;
        MKAnnotationView *pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        DisplayMap *a = (DisplayMap *)annotation;
        pinView.annotation=a;
        if (myid == 1) 
        {
           UIImage *test = [UIImage imageNamed:@"red_dot.png"];
           pinView.image = test;
           pinView.opaque = NO;
       }
       else if (myid == 2)
       {
           UIImage *test = [UIImage imageNamed:@"blue_dot.png"];
           pinView.image = test;
           pinView.opaque = NO;
       }
       else {
           UIImage *test = [UIImage imageNamed:@"green_dot.png"];
           pinView.image = test;
           pinView.opaque = NO;
       }
    return pinView;
  }
  else if ([annotation isKindOfClass:[CalloutAnnotation class]])
  {
       identifier = [NSString stringWithFormat:@"Callout%d",pinView.tag];
       annotationView = [[CalloutAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
       CalloutAnnotation *calloutAnnotation = (CalloutAnnotation *)annotation;
       ((CalloutAnnotationView *)annotationView).title = calloutAnnotation.title;
       ((CalloutAnnotationView *)annotationView).iTag = calloutAnnotation.iTag;
       [annotationView setNeedsDisplay];
       [UIView animateWithDuration:0.5f
                     animations:^(void) {
                         mapView.centerCoordinate = calloutAnnotation.coordinate;
                     }];
       annotationView.annotation = annotation;
       return annotationView;
  }
}


-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view1
{
    if ([view1.annotation isKindOfClass:[DisplayMap class]])
    {
    DisplayMap *pinAnnotation = ((DisplayMap *)view1.annotation);
    LoginDetail *obj =    [[appDelegate mapArray] objectAtIndex:pinAnnotation.iTag];
    [mapView removeAnnotations:annotationRemoveArray];

    CalloutAnnotation *calloutAnnotation = [[CalloutAnnotation alloc] init];
    calloutAnnotation.title      = pinAnnotation.title;
    pinAnnotation.calloutAnnotation = calloutAnnotation;
    [mapView addAnnotation:calloutAnnotation];
    [annotationRemoveArray addObject:calloutAnnotation];
    [self setzoomonselectannotation:pinAnnotation.coordinate];
    }
}

1 个答案:

答案 0 :(得分:0)

标注窗口也是注释视图。那是错的;)

按照提示进行操作: How to customize the callout bubble for MKAnnotationView?

基本上他们说的是:将标注作为引脚本身的子视图