gpt4 book ai didi

ios - 为什么将 subLocality 与反向GeocodeLocation 结合使用时,当前的 subLocality 并不总是弹出

转载 作者:行者123 更新时间:2023-11-30 14:13:46 25 4
gpt4 key购买 nike

我正在创建一个应用程序,告诉用户他们最近的地址是什么。似乎存在一个问题,subLocality 几乎总是不可用。我相信 subLocality 基本上就是您所在的城市,我已经看到过这样的例子,它显示得很好。有什么问题?这是我的代码:

    CLGeocoder().reverseGeocodeLocation(userLocation)
{ (placemarks, error) -> Void in

if error != nil
{
println(error)
}
else
{
let pm = CLPlacemark(placemark: placemarks![0] as CLPlacemark)

var subThoroughtare:String = ""
var thoroughfare:String = ""
var subLocality:String = ""
var subAdministrativeArea:String = ""
var postalCode:String = ""
var country:String = ""

if pm.subThoroughfare != nil {subThoroughtare = pm.subThoroughfare!}
if pm.thoroughfare != nil {thoroughfare = pm.thoroughfare!}
if pm.subLocality != nil {subLocality = pm.subLocality!}
if pm.subAdministrativeArea != nil {subAdministrativeArea = pm.subAdministrativeArea!}
if pm.postalCode != nil {postalCode = pm.postalCode!}
if pm.country != nil {country = pm.country!}
self.addressLabel.text = "\(subThoroughtare) \(thoroughfare) \n \(subLocality) \n \(postalCode) \n \(country)"
}
}

最佳答案

如果目标是让城市使用地点代替

var locality: String! { get } // city, eg. Cupertino

区别在于subLocality实际上是该位置的社区/通用名称。

var subLocality: String! { get } // neighborhood, common name, eg. Mission District

关于ios - 为什么将 subLocality 与反向GeocodeLocation 结合使用时,当前的 subLocality 并不总是弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31460551/

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