我使用反向地理编码从纬度和经度获得地址并设置在标签中。但是文本没有得到多行。因为在运行时单元格高度没有增加,所以我使用表格视图单元格自定义类并在单元格自定义类内部的表格视图中设置数据,我使用下面的函数来获取地址并在cellForRowAt函数中发送参数pdblLatitude和pdblLongitude
func getAdressName(pdblLatitude: String, withLongitude pdblLongitude: String)
{
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) { (placemarks, error) in
if error != nil {
print("Hay un error")
} else {
var addressString : String = ""
let pm = placemarks! as [CLPlacemark]
if pm.count > 0 {
let pm = placemarks![0]
if pm.subLocality != nil {
addressString = addressString + pm.subLocality! + " "
}
if pm.locality != nil {
addressString = addressString + pm.locality! + " "
}
if pm.country != nil {
addressString = addressString + pm.country! + " "
}
print("addressString\(addressString)")
self.lbladdress.text = addressString
self.lbladdress.numberOfLines = 0
self.lbladdress.lineBreakMode = .byWordWrapping
LoadingView.shared.dismiss()
}
}
}
}