Два вывода аннотаций одновременно в MKMapView - PullRequest
0 голосов
/ 20 марта 2012

Я успешно внедрил MKMapVIew и одну аннотацию на своей карте. Я не могу представлять две должности одновременно. Я использую MKMapViewDelegate метод:

mapView:viewForAnnotation:

Может кто-нибудь разобраться в этом.

Спасибо!

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

Это выполнит требование для вас! ...:)

1 Ответ

0 голосов
/ 20 марта 2012

Метод mapView: viewForAnnotation: предназначен только для просмотра аннотаций, например.цвет булавки, метка заголовка и т. д. Если вы хотите показать несколько аннотаций, вы должны выделить и инициализировать все с необходимыми позициями.Например, вы можете создать .plist со всеми координатами и циклом in for, просто добавив их.

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