-1

My code runs perfectly displays all of the placemark values but does not provide sub-administrative area value.

func getAddress(fromLocation location: CLLocation){
        let geoCoder = CLGeocoder()
        geoCoder.reverseGeocodeLocation(location){ (placemarks, error) in
            if let error = error{
                //Alert(title: "Error", message: error.localizedDescription)
            }
            else if let placemarks = placemarks{
                for placemark in placemarks{
                    let address = [
                    placemark.name,
                    placemark.subThoroughfare,
                    placemark.thoroughfare,
                    placemark.locality,
                    placemark.subAdministrativeArea,
                    placemark.administrativeArea,
                    placemark.country,
                    placemark.postalCode]
                    print(address)
                    self.city = placemark.subAdministrativeArea
                    self.country = placemark.country
                }
            }
        }
    }

Output:

enter image description here

4
  • according to the docs at: developer.apple.com/documentation/corelocation/clplacemark all attributes of CLPlacemark are optional, so maybe for that particular location (in Canberra) the subAdministrativeArea is nil.
    – workingdog
    Jan 15 at 13:12
  • It used to provide me subAdministrativeArea value but after a month it stopped providing. I'm wondering if there is something wrong with Apple server or perhaps they have removed cities option and started enforcing suburbs. Jan 15 at 13:49
  • I haven't tried many places, but it works for Sydney, for example, but not for Canberra. Was it working for Canberra before?
    – workingdog
    Jan 15 at 14:09
  • what do you know, it also works for Queanbeyan
    – workingdog
    Jan 15 at 14:15

Browse other questions tagged or ask your own question.