2012-12-12 109 views
8

創建自定義MKAnnoationView如下:定位定製MKAnnotationView

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; 
    MKAnnotationView* customPinView = [[MKAnnotationView alloc] 
              initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier]; 

    UIImage *pinImage = [PowerPlantAnnotation getAnnotationImageForEnergySource:((PowerPlantAnnotation*)annotation).energySource]; 
    customPinView.image = pinImage; 
    return customPinView; 
} 

我得到我想要更多或更少的在正確的位置定位的形象,但並不完全。我的形象看起來是這樣的:

enter image description here

我想要的淚滴底部點對點我的註釋地圖座標,像標準引腳觀點的地圖座標。我怎樣才能做到這一點?目前看起來更像是我的圖像以地圖座標爲中心。

回答

13

默認情況下,註釋視圖中心位於註釋座標處。調整視圖位置設置其centerOffset屬性:

annotationView.centerOffset = CGPointMake(0.0f, -annotationViewHeight/2); 
+0

在這種情況下。視圖的中心在精確的座標位置對齊。引腳的底部應該在精度的座標上。 – carbonr