Ich versuche, die Adresse des Standorts durch reverseGeocodeLocation
zu bekommen, aber manchmal gibt es keine Adresse, was ich will, ist in der Nähe Adresse, wenn reverseGeocodeLocation
gibt keine Adresse für einen bestimmten Ort.Wie erreiche ich die Adresse in der Nähe durch reverseGeocodeLocation, wenn die Standortadresse null ist?
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)
}
}
Ich bekomme keinen Fehler, es ist nur Standort hat keine Adresse, ich bin nur 'reverseGeocodeLocation' angefordert, wenn Ort geändert hat –