【问题标题】:iPhone SDK: MapKit multiple custom annotationsiPhone SDK:MapKit 多个自定义注解
【发布时间】:2010-09-27 11:34:26
【问题描述】:

我可以将大量位置列表加载到我的 MapKit 上,并使用自定义 Pin 图像和注释将它们全部显示出来。

我遇到的问题是我目前的所有注释都显示相同的标题、副标题和 pinImage。

如何制作,以便我可以为每个注释设置自己的标题和不同的 Pin 图? 我很难确定正在通过 mapView:viewForAnnotation 设置的注释。

- (NSString *)subtitle{

    return @"This is the annotation subtitle.";
}

- (NSString *)title{
    return @"Annotations Title";
}

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if (annotation == mapView.userLocation) {
        return nil;
    }

    MKAnnotationView *annView=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);
    UIImage *pinImage = [UIImage imageNamed:@"mapPin.png"];
    annView.image = pinImage;
    return annView;
}

【问题讨论】:

标签: iphone ipad annotations mapkit


【解决方案1】:

您需要将注解对象转换为您的自定义类型并访问它的属性以适当地更改您返回的注解视图。

Apple 的 WeatherMap 示例项目是一个很好的例子,说明了如何做到这一点。 https://developer.apple.com/library/ios/#samplecode/WeatherMap/Introduction/Intro.html

MapCallouts 示例项目的想法相同,但实现更简单。 https://developer.apple.com/library/ios/#samplecode/MapCallouts/Introduction/Intro.html

【讨论】:

  • 嘿,非常感谢。我让我的应用程序结合了这两者,我让它比我最初的计划做得更多。谢谢。
猜你喜欢
  • 2023-03-29
  • 2016-01-25
  • 1970-01-01
  • 1970-01-01
  • 2014-01-13
  • 1970-01-01
  • 2011-06-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多