【问题标题】:Why can't I get mapkit to display a custom annotation pin image?为什么我不能让 mapkit 显示自定义注释图钉图像?
【发布时间】:2010-06-22 06:14:09
【问题描述】:

我认为使用我自己的自定义图钉图像进行注释会非常简单。

但我一直无法让它工作,我也不知道为什么!

我只是在使用:

Annotation *anno = [[[Annotation alloc] init] autorelease];
        anno.coordinate = ridesMap.userLocation.location.coordinate;
        anno.title = @"Current Location";
        anno.subtitle = [NSString stringWithFormat:@"%f, %f", anno.coordinate.latitude, anno.coordinate.longitude];

        static NSString *defaultPinID = @"LocationIdentifier";
        MKPinAnnotationView *pinView = (MKPinAnnotationView *)[ridesMap dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
        if (pinView == nil){
            pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:anno reuseIdentifier:defaultPinID] autorelease];
        }

        pinView.image = [UIImage imageNamed:@"custom_pin.png"];
        pinView.opaque = NO;
        pinView.canShowCallout = YES;
        pinView.draggable = NO;

        pinView.annotation = anno;
        NSLog(@"Adding current location annotation");

        return pinView;

我认为这应该可以工作,因为它需要 UIImage,而且我的项目中确实有 custom_pin.png 文件。

它从不使用我的图像,而只是使用标准的红色别针。我在这里做错了什么?

【问题讨论】:

    标签: iphone annotations mapkit mkmapview


    【解决方案1】:

    来自文档:

    MKPinAnnotationView 类提供了一个具体的注释视图,该视图显示一个图钉图标,就像地图应用程序中的图钉图标一样。

    换句话说,MKPinAnnotationView 将忽略图像属性并始终显示一个图钉。请改用普通的MKAnnotationView

    【讨论】:

    • 是的!那成功了。不知道我是怎么错过的!谢谢。
    • 这个答案为我节省了很多时间。不幸的是,SIMULATOR 有一个 BUG,甚至在我使用 MKPinAnnotationView 时,模拟器向我显示了我设置的正确图像,只是设备没有向我显示图像。我疯了,直到我找到了这篇文章。再次感谢。小心,模拟器是你最大的敌人! :-)
    猜你喜欢
    • 2013-02-28
    • 1970-01-01
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-09
    • 2011-12-27
    • 1970-01-01
    相关资源
    最近更新 更多