【问题标题】:Custom Annotation not showing all自定义注释未显示全部
【发布时间】:2011-01-17 08:11:54
【问题描述】:

好的,我在 mapkit 上有很多图钉。这些图钉显示不同类型的景点。 (例如公园、农场等)

我想为这些不同类型的图钉添加自定义图像。公园有公园形象,反之亦然。

但是,当我添加时,并非所有图像都成功显示。例如,在公园里,它应该有 5 个图钉,但图像只出现在 2 个图钉中,而其他 3 个是默认的红色图钉。

但如果我使用颜色来区分它们。 例如[pinsetPinColor:MKPinAnnotationColorGreen];

有效!有谁知道是什么问题?

相关代码如下。告诉我你是否需要更多。谢谢!

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
if ([annotation isKindOfClass:MKUserLocation.class]) {
    //user location view is being requested,
    //return nil so it uses the default which is a blue dot...
    return nil;
}

//NSLog(@"View for Annotation is called");
MKPinAnnotationView *pin=[[MKPinAnnotationView alloc] 
                          initWithAnnotation:annotation reuseIdentifier:nil];

pin.userInteractionEnabled=TRUE;

MapEvent* event = (MapEvent*)annotation;    
NSLog(@"thetype: %@", event.thetype);


if ([event.thetype isEqualToString:@"adv"]) {
    //[pin setPinColor:MKPinAnnotationColorGreen];
    pin.image = [UIImage imageNamed:@"padv.png"];
}

else if ([event.thetype isEqualToString:@"muse"]){
    //[pin setPinColor:MKPinAnnotationColorPurple];
    pin.image = [UIImage imageNamed:@"pmuse.png"];
}

else if ([event.thetype isEqualToString:@"nightlife"]){
    pin.image = [UIImage imageNamed:@"pnight.png"];

}
else if ([event.thetype isEqualToString:@"parks"]){
    pin.image = [UIImage imageNamed:@"ppark.png"];

}
else if ([event.thetype isEqualToString:@"farms"]){
    pin.image = [UIImage imageNamed:@"pfarm.png"];

}

else {
    [pin setPinColor:MKPinAnnotationColorRed];

}

pin.canShowCallout = YES;
pin.animatesDrop = YES;

UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(clickAnnotation:) forControlEvents:UIControlEventTouchUpInside];
[rightButton setTitle:event.uniqueID forState:UIControlStateNormal];

pin.rightCalloutAccessoryView = rightButton;

return pin;

}

【问题讨论】:

    标签: iphone xcode annotations mapkit


    【解决方案1】:

    大家好,我发现了问题所在。当我设置

    region.span.longitudeDelta = 0.01f;
    region.span.latitudeDelta = 0.01f;  
    

    而不是 0.2f。它实际上设法正确显示所有引脚图像。我认为这与重叠的图像或其他东西有关。不太确定。 :/

    希望这对遇到同样问题的人有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-14
      • 1970-01-01
      • 2016-06-08
      • 1970-01-01
      相关资源
      最近更新 更多