addressDictionary is deprecated: first deprecated in iOS 11.0 - Use @properties

随声附和 提交于 2019-12-06 02:55:16

问题


I'm working with to get locations and address. For i'm getting location successfully but at the time getting address i'm getting warning like,

'addressDictionary' is deprecated: first deprecated in iOS 11.0 - Use @properties

Is any solution for this...


回答1:


Answer in swift - old way commented out:

let street = placemark.thoroughfare! // addressDictionary!["Street"] as? String ?? " "
    let city =  placemark.subAdministrativeArea! // addressDictionary!["City"] as? String ?? " "
    let state = placemark.administrativeArea!//addressDictionary!["State"] as? String ?? " "
    let zip =  placemark.isoCountryCode!// addressDictionary!["ZIP"] as? String ?? " "
    let country = placemark.country! // addressDictionary!["Country"] as? String ?? " "



回答2:


In Swift 5

//let location: CLLocation = CLLocation(latitude: 16.511131, longitude: 80.658725)//Convert lat & lng in to CLLocation

    let geocoder = CLGeocoder()
    geocoder.reverseGeocodeLocation(location) { (placemarksArray, error) in
        print(placemarksArray!)
        if (error) == nil {
            if placemarksArray!.count > 0 {
                let placemark = placemarksArray?[0]
                let address = "\(placemark?.subThoroughfare ?? ""), \(placemark?.thoroughfare ?? ""), \(placemark?.locality ?? ""), \(placemark?.subLocality ?? ""), \(placemark?.administrativeArea ?? ""), \(placemark?.postalCode ?? ""), \(placemark?.country ?? "")"
                print("\(address)")
            }
        }

    }

Result Like :

**print(placemarksArray!) :** [20/19, Road Number 19, 20/19, Road Number 19, Wadala West, Mumbai, 400031, Maharashtra, India @ <+19.01761470,+72.85616440> +/- 100.00m, region CLCircularRegion (identifier:'<+19.01732600,+72.85634600> radius 70.52', center:<+19.01732600,+72.85634600>, radius:70.52m)]

**print("\(address)") :** 20/19, Road Number 19, Mumbai, Wadala West, Maharashtra, 400031, India

In Objective C

if (!(error))
    {
        CLPlacemark *placemark = [placemarks objectAtIndex:0];    
        NSString *address = [NSString stringWithFormat:@"%@, %@, %@, %@, %@, %@",
                             placemark.thoroughfare,
                             placemark.locality,
                             placemark.subLocality, 
                             placemark.administrativeArea, 
                             placemark.postalCode,
                             placemark.country];
        NSLog(@"%@", address);

    }


来源:https://stackoverflow.com/questions/47987473/addressdictionary-is-deprecated-first-deprecated-in-ios-11-0-use-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!