如何使用位置服务获取用户所在的当前邮政编码?
答案 0 :(得分:2)
//finding address given the coordinates
CLGeocoder().reverseGeocodeLocation(location, completionHandler: {(placemarks, error) -> Void in
if error != nil {
print("Reverse geocoder failed with error" + error!.localizedDescription)
return
}
if placemarks!.count > 0 {
let pm = placemarks![0]
print(pm.postalCode) //prints zip code
}
else {
print("Problem with the data received from geocoder")
}
})
答案 1 :(得分:0)
使用CLGeocoder类的reverseGeocodeLocation(_:completionHandler:)方法。