Ios CLGeocoding,反向地理编码并从LAT LONG获取地址以在tableView中显示时面临问题
我是新来的斯威夫特。我有一项任务需要完成。我从服务器得到响应,在那里我得到纬度和经度的数字Ios CLGeocoding,反向地理编码并从LAT LONG获取地址以在tableView中显示时面临问题,ios,swift,tableview,reverse-geocoding,Ios,Swift,Tableview,Reverse Geocoding,我是新来的斯威夫特。我有一项任务需要完成。我从服务器得到响应,在那里我得到纬度和经度的数字 { EndLat = "28.511593"; EndtLong = "77.071136"; }, { EndLat = "28.511593"; EndtLong = "77.071136"; },..... 获取此类型的响应的输入时间超过100秒 现在,当我通过反向地理编码获取地址时 func getA
{
EndLat = "28.511593";
EndtLong = "77.071136";
},
{
EndLat = "28.511593";
EndtLong = "77.071136";
},.....
获取此类型的响应的输入时间超过100秒
现在,当我通过反向地理编码获取地址时
func getAddressForLogOut(pdblLatitude: String, withLongitude pdblLongitude: String) {
if (pdblLatitude != "") && (pdblLongitude != "") {
var center : CLLocationCoordinate2D = CLLocationCoordinate2D()
let lat: Double = Double("\(pdblLatitude)")!
//21.228124
let lon: Double = Double("\(pdblLongitude)")!
//72.833770
let ceo: CLGeocoder = CLGeocoder()
center.latitude = lat
center.longitude = lon
let loc: CLLocation = CLLocation(latitude:center.latitude, longitude: center.longitude)
ceo.reverseGeocodeLocation(loc, completionHandler:
{(placemarks, error) in
if (error != nil)
{
print("reverse geodcode fail: \(error!.localizedDescription)")
}
let pm = placemarks! as [CLPlacemark]
if pm.count > 0 {
let pm = placemarks![0]
print(pm.country)
print(pm.locality)
print(pm.subLocality)
print(pm.thoroughfare)
print(pm.postalCode)
print(pm.subThoroughfare)
var addressString : String = ""
if pm.subLocality != nil {
addressString = addressString + pm.subLocality! + ", "
}
if pm.thoroughfare != nil {
addressString = addressString + pm.thoroughfare! + ", "
}
if pm.locality != nil {
addressString = addressString + pm.locality! + ", "
}
if pm.country != nil {
addressString = addressString + pm.country! + ", "
}
if pm.postalCode != nil {
addressString = addressString + pm.postalCode! + " "
}
print(addressString)
self.endAdd = addressString
print("self.endAdd is",self.endAdd)
}
} )
}
}
我在tableView的CellForRowatineXpath函数中使用了这个函数。当我滚动表格视图时,应用程序会崩溃。在placemark得到零分
让pm=地点标记!在这一行作为[CLPlacemark]
有没有人能帮我使用反向地理编码,让我获取纬度和经度超过100秒的地址,并在tableView中显示出来。CLGeocoder返回一个可选类型:
typealias CLGeocodeCompletionHandler = ([CLPlacemark]?, Error?) -> Void
(来自)
你应该检查一下
我认为使用单元格从geocoder加载数据是个坏主意,因为您将面临一场竞赛:
第4)个单元格显示不一致的数据。什么崩溃?//?placemarks为零让pm=placemarks!作为此行的[CLPlacemark],您不能在cellForRow中调用您的方法。您的方法是异步的。在地理编码发生之前,单元已经返回。