【问题标题】:How to Convert coordinates to address using Swift如何使用 Swift 将坐标转换为地址
【发布时间】:2018-09-26 14:16:15
【问题描述】:

我尝试使用reverseGeocoordinate 在我的DestinationSearchBar 中显示来自locationEnd 的地址,但我不知道该怎么做。

func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
    let camera = GMSCameraPosition.camera(withLatitude: place.coordinate.latitude, longitude: place.coordinate.longitude, zoom: 15.0)

   if locationSelected == .startLocation {
        addressSearchBar.text = "\(place.coordinate.latitude), \(place.coordinate.longitude)"
        locationStart = CLLocation(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
        createMarker(titleMarker: "Punto de recojo", iconMarker: #imageLiteral(resourceName: "marker"), latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
    } else {
        DestinationSearchBar.text = "\(place.coordinate.latitude), \(place.coordinate.longitude)"
        locationEnd = CLLocation(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
        createMarker(titleMarker: "Punto de destino", iconMarker: #imageLiteral(resourceName: "marker"), latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)



    self.mapView.camera = camera
    self.dismiss(animated: true, completion: nil)

}
}

【问题讨论】:

  • 你能详细说明到底是什么不工作吗?如果有错误,请发布错误消息。如果不是,那么您得到的预期结果和实际结果会更容易回答您的问题。
  • 我要改变我提出问题的方式,基本上我想知道的是“怎么做”,我的错误。

标签: ios swift geocoding xcode10


【解决方案1】:

苹果提供反向地理位置api

let address = CLGeocoder.init()
    address.reverseGeocodeLocation(CLLocation.init(latitude: latitude, longitude:longitude)) { (places, error) in
        if error == nil{
            if let place = places{
                //here you can get all the info by combining that you can make address
            }
        }
    }

别忘了导入

import MapKit
import CoreLocation

【讨论】:

  • 是的@MiguelJesusEcheniqueMachado,如果你给它坐标它会起作用,不管你从哪个api获得坐标
猜你喜欢
  • 2021-03-17
  • 1970-01-01
  • 1970-01-01
  • 2014-09-02
  • 2019-09-29
  • 2017-07-05
  • 1970-01-01
相关资源
最近更新 更多