【发布时间】:2017-04-10 08:20:04
【问题描述】:
我试图通过reverseGeocodeLocation 获取位置地址,但有时它返回 nil 地址,如果reverseGeocodeLocation 为任何特定位置返回 nil 地址,我想要获取附近的地址。
public class func getAddressFrom(location: CLLocation, completion:@escaping ((String?) -> Void)) {
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(location) { (placemarks, error) in
if let placemark = placemarks?.first,
let subThoroughfare = placemark.subThoroughfare,
let thoroughfare = placemark.thoroughfare,
let locality = placemark.locality,
let administrativeArea = placemark.administrativeArea {
let address = subThoroughfare + " " + thoroughfare + ", " + locality + " " + administrativeArea
//placemark.addressDictionary
return completion(address)
}
completion(nil)
}
}
【问题讨论】:
标签: ios iphone swift reversegeocodelocation