2017-02-16 4 views
0

私のアプリケーションでは、ユーザーが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; 
    } 
+0

あなたは私の答えを見ましたか? –

+0

私は、注釈についての情報を取得していますが、現在選択されている情報は取得していません。このコードをGetViewForAnnotationメソッドに追加しました。 SculptureTitle.Text = annotationView.Annotation.GetTitle();私が何をやっているのかについての提案は間違っています。現在のディスプレイに注釈が表示されていないようです。 – user3020229

答えて

1

次のようにあなたのカスタムMKAnnotationを作成することができます。

public class AnnotationModel : MKAnnotation 
{ 
    private string _title; 
    private string _subtitle; 

    public AnnotationModel(CLLocationCoordinate2D coordinate, string title, string subtitle = "") 
    { 
     this.Coords = coordinate; 
     _title = title; 
     _subtitle = subtitle; 
    } 

    public override string Title { get { return _title; } } 
    public override string Subtitle { get { return _subtitle; } } 
    public CLLocationCoordinate2D Coords; 
    public override CLLocationCoordinate2D Coordinate { get { return this.Coords; } } 
} 

次に、あなたがあなたのGetViewForAnnotation()方法でこのアノテーションを使用することができます。 詳細はこちらlinkをご覧ください。

+0

基本的に、ユーザーがクリックすると、現在選択されている注釈に関する情報を表示したいだけです。 – user3020229

+0

ねえ、私はそれを手に入れました!それを見つけたので、地図ビューでDidSelectAnnotationViewを呼び出すだけでした。それから、現在選択されている注釈を返したmap.selectedannotationsを呼び出した自分のイベントを追加しました。私は感謝の気持ちを示したカスタムクラスを使って情報を告発しました! – user3020229

+0

map.DidSelectAnnotationView + =(オブジェクト送信者、MKAnnotationViewEventArgs E)=> { \t \t \t \t annoList = map.SelectedAnnotations。 \t \t \t \t foreachの(annoListでIMKAnnotationのA) \t \t \t \t { \t \t \t \t \t SculptureTitle.Text = a.GetTitle()。 \t \t \t \t} \t \t \t} – user3020229

0
map.DidSelectAnnotationView += (object sender, MKAnnotationViewEventArgs e) => 

{annoList = map.SelectedAnnotations。 foreach(annoListのIMKAnnotation a) { SculptureTitle.Text = a.GetTitle(); } };

関連する問題