MKMapView中一次有两个注释针脚

时间:2012-03-20 07:00:24

标签: ios mkmapview mkannotation

我在地图上成功实施了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]];
}

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

1 个答案:

答案 0 :(得分:0)

方法mapView:viewForAnnotation:仅用于注释的视图,例如。引脚的颜色和标题标签等。如果要显示多个注释,则应分配并初始化具有所需位置的所有注释。例如,您可以创建一个包含所有坐标的.plist,并在for循环中添加它们。

修改 这是一个示例代码,取自某处。您必须分配并初始化所有anotations。

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