Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Automatically Display Title/Subtitle on Map Annotation (pin)

I am loading an annotation onto my map view. The annotation displays as a pin when the map is loaded.

However, the title and subtitle do not appear on the pin automatically. Currently, the user is required to tap on the pin before the title displays.

Is there a way to get the title to display automatically on the pin when the map is loaded?

(This question is almost the same thing, but not quite there: To display the title for the current loaction in map in iphone because I already have the -title and -subtitle attributes defined in my object.)

Thanks

like image 796
Anthony C Avatar asked Sep 07 '10 23:09

Anthony C


2 Answers

The method to call is "selectAnnotation:animated" from MKMapView.

like image 125
Anthony C Avatar answered Sep 17 '22 11:09

Anthony C


- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{    
    MKAnnotationView *annotationView = [views objectAtIndex:0];
    id<MKAnnotation> mp = [annotationView annotation];
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate] ,350,350);

    [mv setRegion:region animated:YES];    

    [mapView selectAnnotation:mp animated:YES];

}

if you are doing the same thing which is calling the setRegion method, then make sure that you call

[mapView selectAnnotation:mp animated:YES];

after

[mv setRegion:region animated:YES];    
like image 20
Kassem Avatar answered Sep 18 '22 11:09

Kassem