How to get Lat Long of tapped location in Google Map iOS Swift

你。 提交于 2020-01-07 02:51:22

问题


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:


You can use following delegate method of GMSMapView.

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


来源:https://stackoverflow.com/questions/38530470/how-to-get-lat-long-of-tapped-location-in-google-map-ios-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!