子视图中的谷歌地图

时间:2018-03-08 07:02:53

标签: ios swift google-maps

我在我的应用程序中使用带有标记的谷歌地图。 我能够按住并拖动标记并点击地图并更改标记位置。

现在我想在拖动时或拖动地图时移动标记。 而且我想打印标记位置的地址,因为在触摸时弹出地图。 我在目标c中找到了很多代码,但转换swift对我来说有点困难。我正在附上我的代码,直到我所做的为止。

class ViewController2: UIViewController , GMSMapViewDelegate, CLLocationManagerDelegate {

    @IBOutlet weak var Next: UIButton!
    @IBOutlet weak var MyAnnotation: UIButton!
    @IBOutlet weak var MyMapView: GMSMapView!

    override func viewDidLoad() {
        super.viewDidLoad()
       Next.layer.cornerRadius = 5
        MyMapView.delegate = self

    load()

}

    func load() {

        //map hardcoded

        let camera = GMSCameraPosition.camera(withLatitude: 30.307182, longitude: -97.755996, zoom: 5)

        MyMapView.camera = camera

        MyMapView.delegate = self



        //marker hardcoded

        let marker = GMSMarker()

        marker.position = CLLocationCoordinate2D(latitude: 30.307182, longitude: -97.755996)



        marker.icon = UIImage(named: "Annotation")

        //  london.map = mapView

        marker.map = MyMapView

        ////hardcoded

        marker.isDraggable =  true



    }
 func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {

//        print("You tapped at \(coordinate.latitude), \(coordinate.longitude)")

        print("You tapped at \(coordinate.latitude), \(coordinate.longitude)")

        MyMapView.clear() // clearing Pin before adding new

        let marker = GMSMarker(position: coordinate)

         marker.icon = UIImage(named: "Annotation")

        marker.map = MyMapView

        marker.title = " "

        marker.userData = " "

        marker.isDraggable = true

    }

}

0 个答案:

没有答案