问题
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