简体   繁体   English

如何在iPhone的MKMapView中自定义地图注释图钉?

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

Hello friends, 你好朋友,

I want 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. 我想开发iPhone中的MKMapView功能并以MKAnnotation显示自定义图钉,所以请任何人向我提供链接或有关此功能的任何想法。

Thanks in advance. 提前致谢。

You would need to specify annotation image in the viewForAnnotation delegate method 您需要在viewForAnnotation委托方法中指定注释图像

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM