【发布时间】:2017-03-15 13:43:26
【问题描述】:
我正在使用 swift 3。我无法使用此代码获取像“US”这样的邮政编码并将其保存到 var。
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: {
(placemarks, error) -> Void in
if error != nil {
print("Location Error!")
return
}
if let pm = placemarks?.first {
self.showlocation(pm)
} else {
print("error with data")
}
})
}
func showlocation(_ placemarks: CLPlacemark) {
self.locationm.stopUpdatingLocation()
print("Location done")
// getlocation = placemarks.postalCode! "this string var is nil"
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
print("Location Error: " + error.localizedDescription)
}
代码中没有错误,但如果我刚刚删除“getlocation = placemarks.postalCode!”,应用程序会崩溃该应用程序不会崩溃,但我无法获取邮政编码。它正在 swift 2 上运行。有什么帮助可以解决这个问题吗?
【问题讨论】:
标签: swift swift3 cllocationmanager