How can I show an annotated image on a map?

I have one view -> subview mkmapview.

in that I want to show an image .... my current image is as follows. alt text

and I want to show it as

alt text

How can i do this? how can i add an image to this annotation.

+3
source share
3 answers

In your MKAnnotationView, set the property leftCalloutAccessoryView

leftCalloutAccessoryView View to display the standard callout on the left side of the window.

@property (, ) UIView * leftCalloutAccessoryView . - , . 32 .

UIControl, , . UIControl, .

iOS 3.0 . . @property canShowCallout MapCallouts MKAnnotationView.h

Apple docs

+3

, , leftCalloutAccessoryView MKAnnotationView.

:

leftCalloutAccessoryView .

, :

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

, ,

+7
v.leftCalloutAccessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img"]];

where v is the view of your annotation (MKAnnotationView) Or if you want a complete solution, here it is:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{

    NSString *Identifier = [NSString stringWithFormat:@"%f%f",annotation.coordinate.latitude,annotation.coordinate.longitude];
    MKPinAnnotationView *annView= (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:Identifier];
    if (annView==nil) {
        annView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:Identifier] autorelease];
    }

    if (![annotation isKindOfClass:[MyAnnotation class]]) {
        return nil;
    }

    RightCalloutAccessoryBtn* rightButton = [RightCalloutAccessoryBtn buttonWithType:UIButtonTypeDetailDisclosure];
    annView.rightCalloutAccessoryView = rightButton;
    annView.leftCalloutAccessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img"]] autorelease];
    annView.canShowCallout = YES;
    return annView;
}

You must write this code in your delegate card class.

-1
source

Source: https://habr.com/ru/post/1786923/