Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MKPlacemark pin title

I have my mapview working fine, but the pin that is placed on the map has the title United States. How can I change this title?

    MKCoordinateRegion thisRegion = {{0.0,0.0}, {0.0,0.0}};

        thisRegion.center.latitude = 22.569722;
        thisRegion.center.longitude = 88.369722;

        CLLocationCoordinate2D coordinate;
        coordinate.latitude = 22.569722;
        coordinate.longitude = 88.369722;

        thisRegion.center = coordinate;

        MKPlacemark *mPlacemark = [[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil] autorelease];

        [mapView addAnnotation:mPlacemark];
        [mapView setRegion:thisRegion animated:YES];
like image 935
Jesse Avatar asked Oct 21 '11 19:10

Jesse


2 Answers

Checkout the MKAnnotation Protocol, which MKPlacemark conforms to. You should be able to set the title.

http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKAnnotation_Protocol/Reference/Reference.html

http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKPlacemark_Class/Reference/Reference.html

like image 108
logancautrell Avatar answered Oct 16 '22 02:10

logancautrell


Quite old question, but maybe someone else stumbles upon the same problem (as I did):

Don't add a MKPlacemark to the map's annotations; use MKPointAnnotation instead. This class has title and subtitle properties that are not readonly. When you set them, the annotation on the map is updated accordingly - and this is probably what you want.

To use MKPointAnnotation in your code, replace the lines that allocate and add the MKPlacemark with this code:

MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = coordinate;
annotation.title = NSLocalizedString(@"Dropped Pin",
                                     @"Title of a dropped pin in a map");
[mapView addAnnotation:annotation];

You can set the title and subtitle properties any time later, too. For instance, if you have an asynchronous address query running, you can set the subtitle to the annotation's address as soon as the address is available.

like image 33
Markus Avatar answered Oct 16 '22 02:10

Markus