gpt4 book ai didi

string - 从 CLPlacemark 创建地址字符串

转载 作者:搜寻专家 更新时间:2023-10-31 22:34:36 24 4
gpt4 key购买 nike

谁能建议清洁工从 CLPlacemark 创建地址字符串。

目前我正在使用这个扩展

extension CLPlacemark {

func makeAddressString() -> String {
var address = ""
if subThoroughfare != nil { address = address + " " + subThoroughfare! }
if thoroughfare != nil { address = address + " " + thoroughfare! }
if locality != nil { address = address + " " + locality! }
if administrativeArea != nil { address = address + " " + administrativeArea! }
if postalCode != nil { address = address + " " + postalCode! }
if country != nil { address = address + " " + country! }
return address
}
}

所有实例变量都是可选的,因此检查是否为 nil,我希望街道编号、街道等的顺序相同。

最佳答案

CLPlacemark 具有 CNPostalAddress 类型的 postalAddress 属性。您可以使用 CNPostalAddressFormatter 将其格式化为区域设置感知 字符串。

let formatter = CNPostalAddressFormatter()
let addressString = formatter.string(from: placemark.postalAddress)

关于string - 从 CLPlacemark 创建地址字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32875864/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com