2016-07-22 58 views
0

我想從谷歌地圖視圖中的龍頭位置獲取CLLocationCoordinate2D對象。但是,它總是返回我-180.0,-180.0爲緯度,經度是這樣的:如何在谷歌地圖中獲取緯度龍頭位置Swift

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

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

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

這是在swift 3中工作嗎?因爲這永遠不會觸發我。 – Neo42

+1

@ Neo42查看文檔(位於https://stackoverflow.com/questions/38530470/how-to-get-lat-long-of-tapped-location-in-google-map-ios-swift)是的,這應該適用於Swift 3.你有'GMSMapView'委託集嗎? – BergQuester

相關問題