Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKAnnotation display all pin titles without clicking

I am adding multiple annotations programmatically like this:

- (void)addAnnotations{
    NSInteger i;
    CLLocationCoordinate2D location;

    for ( i = 0 ; i < [storeLatitude count] ; i ++ ){
        location.latitude = [[storeLatitude objectAtIndex:i] floatValue];
        location.longitude = [[storeLongitude objectAtIndex:i] floatValue];

        MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:[listOfStores objectAtIndex:i] andCoordinate:location];
        [self.mapView addAnnotation:newAnnotation];
        [newAnnotation release];    
    }
}

Is it possible to display the title for all pins without clicking on them?

like image 562
Rowie Po Avatar asked Jul 05 '12 09:07

Rowie Po


2 Answers

Declare an array to store all annotation and use MKMapView's setSelectedAnnotations:(NSArray *) method

- (void)addAnnotations {

    NSMutableArray *annotationArray = [[NSMutableArray alloc]init];
    NSInteger i;
    CLLocationCoordinate2D location;

    for ( i = 0 ; i < [storeLatitude count] ; i ++ ) {
        location.latitude = [[storeLatitude objectAtIndex:i] floatValue];
        location.longitude = [[storeLongitude objectAtIndex:i] floatValue];

        MapViewAnnotation *newAnnotation = [[MapViewAnnotation alloc] initWithTitle:    [listOfStores objectAtIndex:i] andCoordinate:location];
        [annotationArray addObject:newAnnotation];
        [self.mapView addAnnotation:newAnnotation];    
    }
    [mapView setSelectedAnnotations:annotationArray];
}
like image 134
Ab'initio Avatar answered Oct 04 '22 04:10

Ab'initio


Try this. It will show the title automatically.

-(void)mapView:(MKMapView *)mapView1 didAddAnnotationViews:(NSArray *)views
{
    [self.mapView selectAnnotation:yourannotationpin animated:NO];
}
like image 45
Madhumitha Avatar answered Oct 04 '22 04:10

Madhumitha