ios - addressDictionary 已弃用 : first deprecated in iOS 11. 0 - 使用@properties

标签 ios objective-c cocoa-touch core-location

我正在使用 获取位置和地址。因为我已成功获取位置,但在获取地址时我收到类似警告,

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

有什么解决办法吗...

enter image description here

最佳答案

在 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)")
            }
        }

    }

结果如:

**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

在 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);

    }

关于ios - addressDictionary 已弃用 : first deprecated in iOS 11. 0 - 使用@properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47987473/

相关文章:

ios - Swift 从网络获取数据

ios - 如何解码从 userDefaults 保存和读取的数组数据 - Swift

ios - 从 ReplayKit 中提取 View 而不在 iOS objective c 中呈现 View Controller

iphone - UILabel 的 sizeToFit/sizeThatFits 忽略 numberoflines 属性

ios - ASIHTTPRequest 获取请求 - 未调用委托(delegate)

ios - 我可以在 iOS 上使用 Quartz Composer 吗?

ios - 为什么我不能将 ContactBody 转换为 SpriteKit 中的自定义 SKNode

ios - 如何在用户滚动时跟踪和记录 UITableViewCell View ?

ios - 在 subview Controller 上禁用点击手势?如何判断是PanGesture还是TapGesture?

iphone - 如何通过餐厅的menuId 获取餐厅?