2012-03-20 5 views
0

MKMapVIewと私のマップ上に1つの注釈を正常に実装しました。私は同時に2つのポストを表現することはできません。誰かがこの事に見ることができMKMapViewの一度に2つの注釈ピン

mapView:viewForAnnotation:

:私はMKMapViewDelegateメソッドを使用しています。

ありがとうございます!

EDIT

- (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 = 22.569722 ; 
region.center.longitude = 88.369722; 
region.span.longitudeDelta = 0.1f; 
region.span.latitudeDelta = 0.1f; 
MKCoordinateRegion anotherRegion = { {0.0, 0.0 }, { 0.0, 0.0 } }; 
anotherRegion.center.latitude = 28.38 ; 
anotherRegion.center.longitude = 77.12; 
anotherRegion.span.longitudeDelta = 90.0f; 
anotherRegion.span.latitudeDelta = 90.0f; 
[mapView setRegion:region animated:YES]; 

[mapView setDelegate:self]; 

DisplayMap *ann = [[DisplayMap alloc] init]; 
ann.title = @" Kolkata"; 
ann.subtitle = @"Mahatma Gandhi Road"; 
ann.coordinate = region.center; 
[mapView addAnnotation:ann]; 
DisplayAnotherMap *annMap = [[DisplayAnotherMap alloc] init]; 
annMap.title = @" New Delhi"; 
annMap.subtitle = @"Shahdara"; 
annMap.coordinate = anotherRegion.center; 
[mapView addAnnotations:[NSArray arrayWithObjects:annMap,ann,nil]]; 
} 

これはあなたのための要件を満たします! ... :)

答えて

0

メソッドmapView:viewForAnnotation:アノテーションのビューだけです。ピンの色とタイトルラベルなど。複数のアノテーションを表示する場合は、必要な位置でallを割り当てて初期化する必要があります。たとえば、すべての座標を持つ.plistを作成し、サイクルのために.plistを追加するだけで済みます。

EDIT これはサンプルコードで、どこかから取得したものです。すべてのアノテーションを割り当てて初期化する必要があります。

-(void)loadDummyPlaces{ 
    srand((unsigned)time(0)); 

    NSMutableArray *tempPlaces=[[NSMutableArray alloc] initWithCapacity:0]; 
    for (int i=0; i<1000; i++) { 

     MyPlace *place=[[MyPlace alloc] initWithCoordinate:CLLocationCoordinate2DMake([self RandomFloatStart:42.0 end:47.0],[self RandomFloatStart:14.0 end:19.0])]; 
     [place setCurrentTitle:[NSString stringWithFormat:@"Place %d title",i]]; 
     [place setCurrentSubTitle:[NSString stringWithFormat:@"Place %d subtitle",i]]; 
     [place addPlace:place]; 
     [tempPlaces addObject:place]; 
     [place release]; 

    } 
    places=[[NSArray alloc] initWithArray:tempPlaces]; 

    [tempPlaces release]; 
} 
+0

私はMKAnnotation委任クラスをインスタンス化しました。注釈をmapVIewに追加しました。しかし、ただ一つしか私には見えません。私は他を見ることができない。 – turtle

+0

コードサンプルで投稿を編集しました... –

+0

ここにMyPlaceとは何ですか? .. – turtle

関連する問題