ios - 使用 Swift 在 Google map 中获取位置详细信息

标签 ios swift google-maps

我的问题有两部分,第一部分我想知道如何在谷歌地图中显示静止图钉,当用户点击 map 时图钉会掉落,给出纬度和经度

第二部分转换这个坐标给我位置名称

最佳答案

对于第一部分,您可以使用谷歌地图 View 的委托(delegate)功能 “ map View :didTapAtCoordinate:”

在此委托(delegate)方法中,您可以在点击的位置添加标记。

let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "your title"
marker.snippet = "your snippet"
marker.map = mapView

在标记的位置,你可以给出你在上面提到的委托(delegate)方法中得到的坐标。

对于第二部分,您可以使用这段代码来获取地址:

您需要导入核心位置:

import CoreLocation
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(currentLocation, completionHandler: {
        placemarks, error in

            if error == nil && placemarks.count > 0 {
                 placemarks.last as? CLPlacemark

            }
        })

此处的 currentLocation 将是您从委托(delegate)方法 didTapAtCoordinate 获得的坐标。

关于ios - 使用 Swift 在 Google map 中获取位置详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54415213/

相关文章:

ios - 静态 UITableViewCell 背景 View

ios - UITableView - 未调用 cellForRowAtIndexPath

ios - 使用 Xcode 6 在 UICollectionView 中继续

ios - 在模块/文件夹级别添加源文档的可能性有哪些?

ios - 无法从 iPhone X 上的双摄像头拍摄双张照片

ios - 执行 FFT 以查找和弦音频样本的基频

javascript - 我的谷歌地图不加载所有位置

javascript - 生成谷歌地图错误

android - 无法运行安卓应用

ios - 从 UIViewController 呈现 UINavigationController