Draggable marker with Google Maps SDK for iOS

后端 未结 4 1355
鱼传尺愫
鱼传尺愫 2021-02-05 13:33

Has anybody figured out how to implement draggable markers with the new Google Maps SDK for iOS? The API does not provide it natively, yet. Feature request is already submitted.

4条回答
  •  迷失自我
    2021-02-05 14:06

    Swift 3.0

    Sweet! All I had to do was add this variable to my marker. Then when carefully select and hold the marker for a moment you can drag it around.

    marker.isDraggable = true  
    

    I have not yet implemented the delegates to save my marker data but here's what it should look like.

    extension MapVC : GMSMapViewDelegate {
    
        func mapView (_ mapView: GMSMapView, didEndDragging didEndDraggingMarker: GMSMarker) {
    
            print("Drag ended!")
            print("Update Marker data if stored somewhere.")
    
        }
    
    }
    

    Note: For a while I was trying to un-animate the screen and marker from floating and animating UP after selected. Now I see that it's a "feature" since your finger is in the way and you can't really see well if it doesn't move the screen during a drag. (Duh!)

提交回复
热议问题