2014-05-03 119 views
0

我跟着这个问题:iOS - MKMapView place annotation by using address instead of lat/long - 为邮政编码创建地图注释,而不是直接为长/纬度值。在地图注释视图上设置标题和副标题

这工作得很好,但是我想设置安诺

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

这不是为标题和副标题工作是只读的标题和副标题。如何更改上面的内容以便我能够设置标题和副标题?

+0

请参考以下内容以进行查询。 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

回答

2

改为使用MKPointAnnotation

示例代码:

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

您不必“专门”使用MKPointAnnotation - 只是一些实现MKAnnotation并具有可设置的标题和副标题的类(如MKPointAnnotation但你可以制作自己的班级)。另外,'locationManager.location.coordinate'应该是'topResult.location.coordinate'。 – Anna

+0

@安娜:没错。更新。谢谢。 – Bhavin

0

你可以试试下面的代码。它可能会帮助你。

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