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?
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];
}
Try this. It will show the title automatically.
-(void)mapView:(MKMapView *)mapView1 didAddAnnotationViews:(NSArray *)views
{
[self.mapView selectAnnotation:yourannotationpin animated:NO];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With