将标记从一个位置拖动到另一位置是否有任何问题?

时间:2019-06-20 07:16:32

标签: ios swift xcode google-maps draggable

首先,如果我长按标记,然后将标记从当前位置拖动到任何自定义位置,但是当我放下标记时,发现它仅使我成为地图中心。

->我设置了代表人
-> scrollGestures是真的

xcode 10.2并使用Google地图。


func mapView(_ mapView: GMSMapView, didEndDragging marker: GMSMarker) {
    print("didEndDragging-->>>>>>")

    MapView.settings.scrollGestures = true

    self.currentLat = mapView.camera.target.latitude
    self.currentLong = mapView.camera.target.longitude


    self.cameraNEW = GMSCameraPosition.camera(withLatitude: self.currentLat , longitude: self.currentLong, zoom: self.zoomLevel)
    self.MapView.camera = self.cameraNEW

    self.marker1.position = CLLocationCoordinate2D(latitude: self.currentLat , longitude: self.currentLong)

    self.marker1.icon = GMSMarker.markerImage(with: .red)

    self.marker1.map = self.MapView

    let loc: CLLocation = CLLocation(latitude:self.currentLat , longitude: self.currentLong)

    let ceo: CLGeocoder = CLGeocoder()
    ceo.reverseGeocodeLocation(loc, completionHandler:
        {(placemarks, error) in
            if (error != nil)
            {
                print("reverse geodcode fail: \(error!.localizedDescription)")
            }
            let pm = placemarks! as [CLPlacemark]

            if pm.count > 0 {
                let pm = placemarks![0]
                var addressString : String = ""
                if pm.name  != nil {
                    addressString = addressString + pm.name! + ", "
                }
                if pm.country != nil {
                    addressString = addressString + pm.country! + ", "
                }
                if pm.postalCode != nil {
                    addressString = addressString + pm.postalCode! + " "
                }

                print(addressString)
                self.txtViewAddress.text = addressString
            }
    })
}

我希望当我拖放标记时,我希望将标记完美地放置在那里。

0 个答案:

没有答案