在MKMapView中一次显示两个注释接点



我成功地在Map上实现了MKMapVIew和单个注释。我不能同时代表两个职位。我使用的是MKMapViewDelegate方法:

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]];
}

这将满足您的要求!…:)

方法mapView:viewForAnnotation:只用于查看注释,例如引脚的颜色和标题标签等。如果你想显示多个注释,你应该分配并初始化所有具有所需位置的注释。例如,您可以创建一个包含所有坐标的.plist,而in For cycle只需将它们相加即可。

编辑这是一个示例代码,取自某处。您必须分配并初始化所有工作站。

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

最新更新