我的问题有两部分,第一部分我想知道如何在谷歌地图中显示静止图钉,当用户点击 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/