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