如何使用自定义地图渲染ios将引脚从a点拖动到b时获取坐标

问题描述 投票:0回答:1

我想把这个OBJC片段翻译成Xamarin表单自定义渲染,我的语法目前无法正常工作。它在引脚拖动过程中崩溃而没有任何错误。

我现在拥有的是什么

protected override void OnElementChanged(ElementChangedEventArgs<View> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                var nativeMap = Control as MKMapView;
                nativeMap.ChangedDragState-= OnDragState;

            }

            if (e.NewElement != null)
            {
                var formsMap = (CustomMap)e.NewElement;
                var nativeMap = Control as MKMapView;
                nativeMap.ChangedDragState+= OnDragState;

            }
        }

        private void OnDragState(object sender, MKMapViewDragStateEventArgs e)
        {
         var NewState = e.NewState;
         var OldState=e.OldState;
         var ShowAnnotation=e.AnnotationView;

         if (OldState==MKAnnotationViewDragState.Dragging) 
         {
         }
         if (NewState == MKAnnotationViewDragState.Ending)
            {
              CLLocationCoordinate2D pinAt = ShowAnnotation.Annotation.Coordinate;
              var droppedLoc = new CLLocation(pinAt.Latitude, pinAt.Longitude);
              geocodeLocation(droppedLoc);


         }
      }

forms xamarin maps mkannotationview
1个回答
1
投票

基于您展示的ObjC:

public override void ChangedDragState(MKMapView mapView, MKAnnotationView annotationView, MKAnnotationViewDragState newState, MKAnnotationViewDragState oldState)
{
    if (oldState == MKAnnotationViewDragState.Dragging)
    {

    }
    if (newState == MKAnnotationViewDragState.Ending)
    {
        var pindropped = annotationView.Annotation.Coordinate;
        var droppedLoc = new CLLocation(pindropped.Latitude, pindropped.Longitude);
        geocodeLocation(droppedLoc);
        mapView.AddAnnotation(_addressAnnotation);
    }
}

注意:你没有为geocodeLocation_addressAnnotation展示ObjC,所以你还需要翻译那些......

© www.soinside.com 2019 - 2024. All rights reserved.