如何在谷歌地图iOS Swift中获取Lat Long的位置 [英] How to get Lat Long of tapped location in Google Map iOS Swift

查看:191
本文介绍了如何在谷歌地图iOS Swift中获取Lat Long的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从Google地图视图中的轻触位置获取CLLocationCoordinate2D对象。但它总是以-180.0,-180.0为单位,如下所示:

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)
     }
}


推荐答案

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

You can use following delegate method of GMSMapView.

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

这篇关于如何在谷歌地图iOS Swift中获取Lat Long的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆