开发者

How to customize the map annotation pin in MKMapView with iPhone?

Hello friends,

I wan开发者_开发技巧t to develop a functionality MKMapView in iPhone and to show the custom pin in MKAnnotation so please could anyone provide me a link or any idea about this functionality.

Thanks in advance.


You would need to specify annotation image in the viewForAnnotation delegate method

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {
        static NSString * const kAnnotationId = @"VumeliveAnnotation";

    MKPinAnnotationView *annotationView = nil;
    if ([annotation isKindOfClass:[CustomAnnotation class]])
    {
        annotationView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:kAnnotationId];
        if (annotationView == nil) {
            annotationView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:kAnnotationId] autorelease];
            annotationView.canShowCallout = YES;
            annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        }

        [annotationView setImage:[UIImage imageNamed:<your image name>]];
    }

    return annotationView;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜