在我的應用程序,當用戶點擊一個註解爲我UITextviews顯示有關注釋如標題,緯度和經度一些更具描述性信息,我想一個視圖中顯示。我的問題是,我不知道在註釋添加到地圖後如何獲取這些信息。這裏是我用於MKAnnotationView的一些代碼,它只是內置到我的自定義視圖控制器中。獲取當前的註釋信息以在xamarin的iOS
MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
{
MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(annotationIdentifier);
// Set current location and location of annotation
CLLocationCoordinate2D currentLocation = mapView.UserLocation.Coordinate;
CLLocationCoordinate2D annotationLocation = annotation.Coordinate;
// We don't want a special annotation for the user location
if (currentLocation.Latitude == annotationLocation.Latitude && currentLocation.Longitude == annotationLocation.Longitude)
return null;
if (annotationView == null)
annotationView = new MKPinAnnotationView(annotation, annotationIdentifier);
else
annotationView.Annotation = annotation;
annotationView.CanShowCallout = true;
(annotationView as MKPinAnnotationView).AnimatesDrop = false; // Set to true if you want to animate the pin dropping
(annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Red;
annotationView.SetSelected(true, false);
_annotationDetailButton = UIButton.FromType(UIButtonType.DetailDisclosure);
_annotationDetailButton.TouchUpInside += (sender, e) =>
{
//put create segue her
PerformSegue("ShowCollectionDetail", Self);
};
annotationView.RightCalloutAccessoryView = _annotationDetailButton;
// Annotation icon may be specified like this, in case you want it.
// annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromBundle("example.png"));
return annotationView;
}
你看看我的答案? –
我做了,我得到關於註釋的信息,但不是當前選擇的註釋。我將此代碼添加到GetViewForAnnotation方法。 SculptureTitle.Text = annotationView.Annotation.GetTitle();對於我仍然做錯的任何建議。看來我得到的註釋不在當前顯示。 – user3020229