当用户点击覆盖时,我试图显示标注。然后,标注上有一个基于所选叠加层的标题。我希望仅在用户点击叠加层时才显示注释。但问题是覆盖层无法识别水龙头,并且所有注释在开始时都是可见的。我要他们隐藏。
一个类似的问题是here。但我想不通。 点击覆盖时显示标注
覆盖协调从服务器下载并添加如下:
//Add a polygon
MKPolygon *rect=[MKPolygon polygonWithCoordinates:parkingCords count:5];
[self.mapView addOverlay:rect];
[self.mapView addAnnotation:rect];
现在,每个叠加层的中心都有一个注释。
查看注解
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
...
else if([annotation isKindOfClass:[MKPolygon class]]){
NSLog(@"MKPOLYGON CLASS");
static NSString *identifier3 = @"else";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier3];
if (annotationView == nil) {
annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier3];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
} else {
annotationView.annotation = annotation;
}
...
}
viewForOverlay
-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay{
if([overlay isKindOfClass:[MKPolygon class]]){
MKPolygonView *view = [[MKPolygonView alloc] initWithOverlay:overlay];
view.lineWidth=1;
view.strokeColor=[UIColor blueColor];
view.fillColor=[[UIColor blueColor] colorWithAlphaComponent:0.3];
recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(overlayTapped)];
recognizer.delegate=self;
[view addGestureRecognizer:recognizer];
[recognizer release];
return view;
}
return nil;
}
-(void)overlayTapped{
NSLog(@"overlay tapped");
//[self.mapView setSelectedAnnotations:?????];
}