2013-11-04 36 views
1

請讓我知道如何使圖像顯示在中心點。 讓我詳細說明。 我有MapPin自定義圖像,但圖像看起來是這樣的如何使地圖釘(自定義)圖像出現在中心點

enter image description here

如果你仔細看的話,針落在正確的緯度和長,但圖像的中心是是圓形部分落在拉特和長。由此拉長似乎是在不同的位置(見針基)。 但是,我們想要的是針腳落在該位置(緯度和長度)。 像這樣的東西..(請參閱第二張圖片) 請不要告訴我改變圖像的高度和寬度,因爲有300張圖像。 除非和直到這是唯一的選擇,或者我可以通過編程來改變它。

請幫助這個可悲的問題。

謝謝你好朋友。

enter image description here

+1

在viewForAnnotation中,是否正確設置'centerOffset'?請參閱http://stackoverflow.com/questions/13492231/change-the-images-origin-of-map-annotation-view。 – Anna

+0

@AnnaKarenina:鏈接幫助我達到了很大的程度。但不幸的是我無法獲得正確的緯度/長度的引腳。 我是否需要針對每個針腳有不同的centerOffset,因爲我有4個針腳,同時應用centerOffset,它似乎只適用於單個針腳而不是所有針腳。 – iCodeAtApple

+0

@AnnaKarenina:終於!!!我爲每個引腳使用了不同的偏移量。儘管準確放置每個引腳花費了我很長時間,但最終我實現了它。由於MichaelO發佈了答案,我會接受他的。 但我不能否認安娜卡列尼娜的評論在很大程度上有幫助,所以我在她發佈的鏈接上投了她的答案。 非常感謝你們。 ! – iCodeAtApple

回答

1

您可以使用centerOffset根據圖像大小移動位置。

例如與絕對偏移量:

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 

    static NSString* const annIdentifier = @"annotationidentifier"; 
    PinAnnotationView* myPinView = [[[PinAnnotationView alloc] initWithAnnotation:annotation  reuseIdentifier:annIdentifier] autorelease]; 

    myPinView.centerOffset = CGPointMake(0, -10.0f); 

    return myPinView; 
} 

根據您的個人圖像大小用計算值替換這些絕對值。

0

我在一個測試應用程序做這樣的事情。

我把這段代碼放在這裏,你可以自己定製它,我希望這會幫助你。

在超級視圖沒有負載,我有

MapAnnotation *安= [[MapAnnotation的alloc] INIT];

MKCoordinateRegion region; 
region.center.latitude = 31.504679; 
region.center.longitude = 74.247429; 
region.span.latitudeDelta = 0.01; 
region.span.longitudeDelta = 0.01; 

[mapView setRegion:region animated:YES]; 




ann.title = @"Digital Net"; 
ann.subtitle = @"Office"; 
ann.coordinate = region.center; 

[mapView addAnnotation:ann]; 
+0

iOS學習者:我嘗試使用該區域作爲所有引腳通用的區域,並在添加引腳後將其設置爲映射。但不幸的是...沒有工作。 – iCodeAtApple

+0

你找到解決方案還是存在問題 –

+0

iOS學習者:我確實找到解決方案,請檢查上面的評論,所以我接受你的答案。 – iCodeAtApple

相關問題