How to get formatted address NSString from AddressDictionary?

前端 未结 9 1407
旧巷少年郎
旧巷少年郎 2020-12-17 14:58

Trying to get formatted address from AddressDictionary, that I got from CLGeocoder. Used following code with no result:

subtitle = [NSString stringWithString         


        
9条回答
  •  旧巷少年郎
    2020-12-17 15:33

    I am using Swift 3 / XCode 8

    ZYiOS's answer was nice and short but did not compile for me.

    The question asks how to get from an existing Address Dictionary to a string address. This is what I did:

    import CoreLocation
    
    func getAddressString(placemark: CLPlacemark) -> String? {
        var originAddress : String?
    
        if let addrList = placemark.addressDictionary?["FormattedAddressLines"] as? [String]
        {
            originAddress =  addrList.joined(separator: ", ")
        }
    
        return originAddress
    }
    

提交回复
热议问题