How to get formatted address NSString from AddressDictionary?

前端 未结 9 1411
旧巷少年郎
旧巷少年郎 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:38

    Swift 3 / Xcode 8 Helper Mehtod to get address from CLPlaceMark

    class func formattedAddress(fromPlacemark placemark: CLPlacemark) -> String{
        var address = ""
    
        if let name = placemark.addressDictionary?["Name"] as? String {
            address = constructAddressString(address, newString: name)
        }
    
        if let city = placemark.addressDictionary?["City"] as? String {
            address = constructAddressString(address, newString: city)
        }
    
        if let state = placemark.addressDictionary?["State"] as? String {
            address = constructAddressString(address, newString: state)
        }
    
        if let country = placemark.country{
          address = constructAddressString(address, newString: country)
        }
    
        return address
      }
    

提交回复
热议问题