How to get Lat Long of tapped location in Google M

2019-09-12 03:04发布

I am trying to get the CLLocationCoordinate2D object from the tapped location in a google map view. But it always return me -180.0, -180.0 as lat,long like this:

CLLocationCoordinate2D(latitude: -180.0, longitude: -180.0)

I am using following code for this:

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条回答
走好不送
2楼-- · 2019-09-12 03:12

You can use following delegate method of GMSMapView.

func mapView(mapView: GMSMapView!, didTapAtCoordinate coordinate: CLLocationCoordinate2D) {
    println("You have lat and long")
}
查看更多
登录 后发表回答