You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xamarin.Forms如何在MapView上创建可拖动标记(Marker)?

Draggable Markers in Xamarin.Forms Maps: Getting Started

Hi there! Since you already have Android and Swift development experience, you’ll catch on to this fast. Here’s your starting direction for implementing draggable markers (since the out-of-the-box Xamarin.Forms.Map only supports basic Pins):

  • Use Custom Renderers: This is the go-to way to tap into native platform features in Xamarin.Forms. You’ll build platform-specific renderers for your Map control to hook into the native Google Maps (Android) and MapKit (iOS) APIs you already know.
    • For Android:
      • Create a custom renderer that inherits from MapRenderer
      • Access the native GoogleMap instance in the renderer
      • When creating native Markers from your Forms Pins, set Draggable = true
      • Listen to native drag events (MarkerDragStart, MarkerDrag, MarkerDragEnd) and pass these events back to a custom Xamarin.Forms Map subclass (you’ll need to define this subclass with drag event handlers)
    • For iOS:
      • Build a custom renderer inheriting from MapRenderer
      • Get the native MKMapView
      • For the MKAnnotationView corresponding to your Forms Pin, set Draggable = true
      • Implement the MKMapViewDelegate methods like DidDragAnnotationView to handle drag events and relay them to your Forms-level Map control
  • Optional: Custom DraggablePin Class: Define a subclass of Pin (e.g., DraggablePin) to flag which pins should be draggable. This makes it easier to handle only specific pins in your renderers instead of all pins.

内容的提问来源于stack exchange,提问作者TJBlack31

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:53:09