为什么我无法让 Mapkit 显示自定义注释图钉图像?

发布于 2024-09-06 05:05:25 字数 1134 浏览 1 评论 0原文

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

但我从来没能让它发挥作用,我也不知道为什么!

我只是使用:

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 文件。

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

I figured that using my own custom pin image for annotations would be super easy.

But I have never been able to get it to work, and I have no idea why!

I am simply using:

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;

I assumed that this should work, as a UIImage is what it is wanting, and I do have the custom_pin.png file in my project.

It never uses my image, but just the standard red pin. What am I doing wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蹲在坟头点根烟 2024-09-13 05:05:25

来自文档:

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

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

From the docs:

The MKPinAnnotationView class provides a concrete annotation view that displays a pin icon like the ones found in the Maps application.

In other words, a MKPinAnnotationView will ignore the image property and always display a pin. Use a regular MKAnnotationView instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文