不推荐使用addressDictionary:在iOS 11.0中首先不推荐使用-使用@properties [英] addressDictionary is deprecated: first deprecated in iOS 11.0 - Use @properties

查看:486
本文介绍了不推荐使用addressDictionary:在iOS 11.0中首先不推荐使用-使用@properties的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与您联系以获取位置和地址。因为我成功地获得了位置,但是在获得地址时却得到了警告,

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

推荐答案

在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

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

    }

这篇关于不推荐使用addressDictionary:在iOS 11.0中首先不推荐使用-使用@properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆