Xamarin IOS可拖动Google Map Marker

时间:2019-03-15 12:32:27

标签: google-maps xamarin.forms xamarin.ios xamarin-studio

我正在尝试在iOS中拖动标记(Google Map API iOS)。我不确定我要去哪里错。我可以在Google地图上看到标记,但是标记没有拖动。 我使用了自定义渲染器局部视图来显示地图。以下是代码:

[assembly: ExportRenderer(typeof(RegisterFacilityIOSMapView), typeof(RegisterFacilityMapViewRenderer))]
namespace RadLoc.iOS.Renderers
{
public class RegisterFacilityMapViewRenderer : ViewRenderer
{
    MapView mapView;
    CLLocationManager LocMgr;
    Marker marker;
    CameraPosition camera;

    protected override void OnElementChanged(ElementChangedEventArgs<View> e)
    {
        base.OnElementChanged(e);
        try
        {
            LocMgr = CLLocationManagerSingleton.Instance;
            camera = CameraPosition.FromCamera(latitude: LocMgr.Location.Coordinate.Latitude, longitude: LocMgr.Location.Coordinate.Longitude, zoom: 10);
            mapView = MapView.FromCamera(CGRect.Empty, camera);
            //mapView.MyLocationEnabled = true;
            mapView.AddObserver(this, new NSString("My Location"), NSKeyValueObservingOptions.New, IntPtr.Zero);
            mapView.UserInteractionEnabled = true;
            SetNativeControl(mapView);

            UIImage color = Marker.MarkerImage(UIColor.FromRGB(87, 188, 236));

            var circleCenter = new CLLocationCoordinate2D(LocMgr.Location.Coordinate.Latitude, LocMgr.Location.Coordinate.Longitude);
            marker = Marker.FromPosition(circleCenter);
            marker.UserData = new Foundation.NSObject();
            //marker.Position = circleCenter;
            marker.Icon = color;
            marker.Title = "My Loc";
            marker.ZIndex = 9999;
            marker.Draggable = true;


            mapView.DraggingMarkerStarted += (s, ee) =>
            {

            };
            mapView.DraggingMarkerEnded += (s, ee) =>
            {

            };
            mapView.DraggingMarker += (s, ee) =>
            {

            };
            marker.Map = mapView;

            marker.Draggable = true;
        }
        catch (Exception ee)
        {

        }
    }
  }
}

0 个答案:

没有答案