![](/img/trans.png)
[英]Why does current subLocality not always pop up when using subLocality with reverseGeocodeLocation
[英]How to show the current state you are located in when using reverseGeocodeLocation in swift
我正在使用这个显示您最近地址的应用程序测试reverseGeocodeLocation。 我已经完成了所有工作,除了显示你所在的当前状态(IL,NY,分机)。 我怎么做? 这是我目前的代码:
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)"
}
}
输出是这个(示例位置):
County Road 1760
79529
United States
let state = pm.administrativeArea;
如果你看一下它所显示的CLPlacemark类的定义..
var administrativeArea: String! { get } // state, eg. CA
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.