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

How to obtain the coordinates when a pin drag from point a to b using custom map render ios

我想将此 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);


         }
      }

根据您展示的 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,因此您还需要翻译它们...