开发者

how can I show an image in map pin annotation?

i have one view >> subview mk开发者_如何学Gomapview .

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

how can I show an image in map pin annotation?

and i want to show like this

how can I show an image in map pin annotation?

how can i do this ? how can i add image in this anotation.


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


In your MKAnnotationView set the leftCalloutAccessoryView property

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

@property (retain, nonatomic) UIView *leftCalloutAccessoryView Discussion The default value of this property is nil. The left callout view is typically used to display information about the annotation or to link to custom information provided by your application. The height of your view should be 32 pixels or less.

If the view you specify is also a descendant of the UIControl class, you can use the map view’s delegate to receive notifications when your control is tapped. If it does not descend from UIControl, your view is responsible for handling any touch events within its bounds.

Availability Available in iOS 3.0 and later. See Also @property canShowCallout Related Sample Code MapCallouts Declared In MKAnnotationView.h

Apple docs


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

where v - is the view of your annotation(MKAnnotationView) Or if you want 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 should write this code on the class of your map's delegate

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜