2011-06-12 34 views
7

我有一個使用iphone地圖套件的應用程序。它顯示了一組標準的引腳。 現在我切換到針腳定製圖像(使用MKMapViewDelegate)iPhone定製針位置問題

問題是,自定義引腳不居中右 - 定製引腳指向靠近原來的位置。

問題是iphone如何使用自定義引腳。例如:讓我們有一個針對50x50像素的圖像。我們有全球座標(長,拉特):XY

iphone中心圖像如何?

謝謝

回答

9

如果您分配您的自定義圖像輸出到圖像屬性。當顯示註釋時,圖像以目標地圖座標爲中心顯示。如果不希望圖像在地圖座標上居中,則可以使用centerOffset屬性在任何方向上水平和垂直移動中心點。

因此,自定義圖像僅顯示在目標座標的中心。

MKAnnotationView* aView = [[[MKAnnotationView alloc] initWithAnnotation:annotation 

            reuseIdentifier:@"MyCustomAnnotation"] autorelease]; 

aView.image = [UIImage imageNamed:@"myimage.png"]; 

aView.centerOffset = CGPointMake(10, -20);  

Source: apple class reference for MKMapView

6

的解決方案是設置在中心的MapView的代表偏移和在註釋查看它自:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    static NSString* const kPinIdentifier = @"pinidentifier"; 

    PinAnnotationView* customPinView = [[[PinAnnotationView alloc] 
              initWithAnnotation:annotation reuseIdentifier:kPinIdentifier] autorelease]; 
    customPinView.canShowCallout = NO; 

    // Here !! 
    customPinView.centerOffset = CGPointMake(0, -21.5f); 

    return customPinView; 
}