最近,我遇到了一个非常严重的错误,当尝试使用反向地理编码来获取城市和国家/地区时,我的应用程序崩溃了。 有人可以帮我解决这个烦人的问题吗? 预先感谢
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation :CLLocation = locations[0] as CLLocation
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(userLocation) { (placemarks, error) in
if (error != nil){
print("error in reverseGeocode")
}
let placemark = placemarks! as [CLPlacemark] ///shows error here :(
if placemark.count>0{
let placemark = placemarks![0]
self.lblLocation.text = "\(placemark.locality!), \(placemark.country!)"
}
}
}