How do I move marker along with moving of Google Map in iOS?

前端 未结 4 1892
一个人的身影
一个人的身影 2020-12-24 15:37

I am displaying a marker in a particular place, along with displaying the current address in the address label on Google Maps.

Now, I want to change the location by

4条回答
  •  猫巷女王i
    2020-12-24 16:11

    Update for Swift 4:

    First you need to conform with the GMSMapViewDelegate:

    extension MapsVC: GMSMapViewDelegate{
    

    And then set your VC as the delegate of viewMap in the viewDidLoad()

    viewMap.delegate = self
    

    After that you just need to use the following method to get updates from the camera position and set that as the new position for the marker:

    func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
        destinationMarker.position = position.target
        print(destinationMarker.position)
    }
    

提交回复
热议问题