2014-05-03 299 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];