如何在Google Map iOS Swift中获取点击位置的Lat长度

如何在Google Map iOS Swift中获取点击位置的Lat长度,ios,swift,google-maps,cgpoint,cllocationcoordinate2d,Ios,Swift,Google Maps,Cgpoint,Cllocationcoordinate2d,我试图从google地图视图中点击的位置获取CLLocationCoordinate2D对象。但它总是返回我-180.0,-180.0作为lat,长得像这样: CLLocationCoordinate2D(latitude: -180.0, longitude: -180.0) 我正在为此使用以下代码: override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { let to

我试图从google地图视图中点击的位置获取CLLocationCoordinate2D对象。但它总是返回我-180.0,-180.0作为lat,长得像这样:

CLLocationCoordinate2D(latitude: -180.0, longitude: -180.0)
我正在为此使用以下代码:

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
{
     let touchpoint = touches.first

     if let touch = touches.first
     {
        var point: CGPoint = touch.locationInView(self.view)

        let touchMapCoordinate: CLLocationCoordinate2D = MyMapView.projection.coordinateForPoint(point)
     }
}
覆盖函数触摸开始(触摸:设置,withEvent事件:UIEvent?)
{
让touchpoint=touchs.first
如果让触摸=先触摸
{
变量点:CGPoint=touch.locationInView(self.view)
让touchMapCoordinate:CLLocationCoordinate2D=MyMapView.projection.coordinateForPoint(点)
}
}

您可以使用
GMSMapView
的以下委托方法

func mapView(mapView: GMSMapView!, didTapAtCoordinate coordinate: CLLocationCoordinate2D) {
    println("You have lat and long")
}

您可以使用
GMSMapView
的以下委托方法

func mapView(mapView: GMSMapView!, didTapAtCoordinate coordinate: CLLocationCoordinate2D) {
    println("You have lat and long")
}

这在swift 3中有效吗?因为这对我来说永远不会触发。@Neo42查看文档(位于)是的,这应该适用于Swift 3。您有
GMSMapView
代理集吗?这在swift 3中有效吗?因为这对我来说永远不会触发。@Neo42查看文档(位于)是的,这应该适用于Swift 3。您是否设置了
GMSMapView
代理?