how can I show an image in map pin annotation?

后端 未结 3 1402
谎友^
谎友^ 2021-02-06 17:58

i have one view >> subview mkmapview .

in that i want to show image . ...my current image is like this.\"alt

3条回答
  •  误落风尘
    2021-02-06 18:52

    The image you're talking about corresponds to the leftCalloutAccessoryView property of MKAnnotationView.

    Extract from the doc :

    leftCalloutAccessoryView The view to display on the left side of the standard callout bubble.

    You can implement a methods such as this :

    - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation {
    
        MKAnnotationView* annotationView = nil;
    
        MyAnnotation *myAnnotation = (MyAnnotation*) annotation;
        NSString* identifier = @"Pin";
        MKPinAnnotationView* annView = (MKPinAnnotationView*)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    
        if(nil == annView) {
            annView = [[[MKPinAnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];
        }
    
        UIImageView *leftIconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"LeftIconImage.png"]];
        annView.leftCalloutAccessoryView = leftIconView;
    
        return annotationView;
    }
    

    Hope this helps, Vincent

提交回复
热议问题