1

I followed this question: iOS - MKMapView place annotation by using address instead of lat / long - to create a map annotation for a postal code as opposed to the long/lat values directly.

This works fine, however I would like to set the title and subtitle of the anno

CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc] 
placemark.title = self.business.businessName;
placemark.subtitle = self.business.phoneNumber;

This is not working as the title and subtitle are readonly. How can I change the above so that I am able to set the title and subtitle?

Community
  • 1
  • 1
StuartM
  • 6,743
  • 18
  • 84
  • 160
  • Please refer the following for your query. http://stackoverflow.com/questions/20645723/show-address-in-annotation-when-pin-is-dropped-on-map http://stackoverflow.com/questions/21541989/how-to-add-callout-into-individual-annotation-in-map-view – VRAwesome May 03 '14 at 12:55

2 Answers2

3

Use MKPointAnnotation instead.

Sample Code :

CLPlacemark *topresult = [placemarks objectAtIndex:0];
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
annotation.coordinate = topresult.location.coordinate;
annotation.title = self.business.businessName;
annotation.subtitle = self.business.phoneNumber;
[self.mapView addAnnotation:annotation];
Bhavin
  • 27,155
  • 11
  • 55
  • 94
  • 1
    You don't "have to" use MKPointAnnotation specifically -- just some class that implements MKAnnotation and has a settable title and subtitle (like MKPointAnnotation but you could make your own class). Also, `locationManager.location.coordinate` should be `topResult.location.coordinate`. –  May 03 '14 at 13:01
0

You can try below code. It may help you.

//set the title if we got any placemarks...
if (placemark.count > 0)
{
    CLPlacemark *topResult = [placemark objectAtIndex:0];
    annTitle = [NSString stringWithFormat:@"%@ %@ %@ %@", topResult.country, topResult.locality, topResult.subLocality, topResult.thoroughfare];
}

//now create the annotation...
MapAnnotation *toAdd = [[MapAnnotation alloc]init];

toAdd.coordinate = touchMapCoordinate;
toAdd.title = @"Address";
toAdd.subtitle = @"Sub Address";

[self.map addAnnotation:toAdd];
VRAwesome
  • 4,721
  • 5
  • 27
  • 52