【问题标题】:Annotation on MapKit pin not showingMapKit pin上的注释未显示
【发布时间】:2012-03-08 14:52:53
【问题描述】:

我在地图上放置了两个图钉,单击时每个图钉都有一个注释,但是,只显示StoreLocationOne 的注释。地图上的两个图钉都显示出来了,但是点击时没有显示 StoreLocationTwo 注释,有什么想法吗?

-(void)viewDidLoad {
    [super viewDidLoad];

    [mapview setMapType:MKMapTypeStandard];
    [mapview setZoomEnabled:YES];
    [mapview setScrollEnabled:YES];

    MKCoordinateRegion region = { {0.0, 0.0 }, {0.0, 0.0 } };
    region.center.latitude = 57.132053;
    region.center.longitude = -2.135592;
    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;
    [mapview setRegion:region animated:YES];

    StoreLocationOne *ann = [[StoreLocationOne alloc] init];
    ann.title = @"Heavenly Pizzas Mannofield";
    ann.subtitle = @"483a Great Western Rd, Aberdeen, AB10 6NN";
    ann.coordinate = region.center;
    [mapview addAnnotation:ann];

    MKCoordinateRegion region2 = { {0.0, 0.0 }, {0.0, 0.0 } };
    region2.center.latitude = 57.232458;
    region2.center.longitude = -2.347853;
    region2.span.longitudeDelta = 0.01f;
    region2.span.latitudeDelta = 0.01f;

    StoreLocationTwo *ann2 = [[StoreLocationTwo alloc] init];
    ann2.title2 = @"Heavenly Pizzas Kintore";
    ann2.subtitle2 = @"School Road, Kintore, AB51 0UU";
    ann2.coordinate = region2.center;
    [mapview addAnnotation:ann2];

}

【问题讨论】:

    标签: ios sdk annotations mapkit


    【解决方案1】:

    titlesubtitle 属性必须准确命名。地图视图不会知道寻找title2subtitle2

    您可以有多个实现MKAnnotation 的类,但属性名称必须符合协议。

    此外,如果您只需要属性coordinatetitlesubtitle,则可以使用内置注释类MKPointAnnotation,而不是为每个坐标创建单独的类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-05
      相关资源
      最近更新 更多