Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top