2012-03-20 96 views
0

我成功實現了MKMapVIew和我的Map上的單個註釋。我無法同時代表兩個郵筒。我使用MKMapViewDelegate方法:MKMapView中的兩個註釋引腳

mapView:viewForAnnotation:

有人可以看看這個東西。

謝謝!

編輯

- (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:僅用於註釋的視圖,例如。插針的顏色和標題標籤等。如果要顯示多個註釋,則應分配並初始化所有需要的位置。例如,您可以創建一個包含所有座標的.plist,並在for for循環中添加它們。

編輯 這是一個示例代碼,取自某處。你必須分配和初始化所有的註解。

-(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 2012-03-20 07:22:41

+0

我使用代碼示例編輯帖子... – 2012-03-20 07:35:17

+0

什麼是MyPlace這裏? .. – turtle 2012-03-20 09:06:33