如何在谷歌地图iOS Swift中获取Lat Long的点击位置

时间:2016-07-22 15:39:02

标签: ios swift google-maps cgpoint cllocationcoordinate2d

我正试图从谷歌地图视图中的tapped位置获取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)
     }
}

1 个答案:

答案 0 :(得分:1)

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

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