我尝试使用reverseGeocoordinate
在我的locationEnd
上显示DestinationSearchBar
的地址,但是我不知道该怎么做。
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)
}
}
答案 0 :(得分:2)
Apple提供反向地理位置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