2011-01-17 15 views
0

いいえ、マップキットにはピンがいくつかあります。これらのピンはさまざまな種類のアトラクションを示しています。 (公園、農場など)カスタムアノテーションがすべて表示されていません

これらのさまざまな種類のピンにカスタム画像を追加したいとします。公園には公園のイメージがあり、その逆もあります。

私が追加したとき、すべての画像が正常に表示されるわけではありません。たとえば、公園では5ピンが必要ですが、イメージは2ピンのみで、他の3ピンはデフォルトの赤ピンです。

しかし、私はそれらを区別するために色を使用しています。 たとえば、[pinsetPinColor:MKPinAnnotationColorGreen];

これは機能します。誰が問題が分かっているのですか?

下記の関連コード。もっと必要があるかどうか教えてください。ありがとう!

答えて

0

は、このリンクからの助けを取る@funatsg

- (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; 

} ...... http://blog.asolutions.com/2010/09/building-custom-map-annotation-callouts-part-1/

・ホープこれはあなたの問題を解決します!

+0

Heys!迅速な返信をいただきありがとうございますが、実際にピンに問題がありますが、コールアウトではありません。何か案は? – funatsg

0

ねえ、私は問題が何かを知った。私が設定したとき

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

の代わりに0.2f。実際にはすべてのピン画像を正しく表示することができます。私は、重複しているイメージや何かと関係があると思う。あまり確かではありません。 :/

これは、同じ問題を抱えている人に役立ちます。

関連する問題