【发布时间】:2017-05-13 07:28:47
【问题描述】:
如何在每个 tableview 行单元格中反转地理编码位置?
我有一个表格视图控制器,其中每个超级请求都以纬度和经度的形式出现。如何将每个坐标转换为 tableviewcontroller 中的实际地址?
cellForRowAt 中的代码如下:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if self.rideRequests.count != 0 {
let request = self.rideRequests[indexPath.row]
if let cell = tableView.dequeueReusableCell(withIdentifier: "RequestsCell") as? RequestsCell {
cell.configureCell(requests: request)
return cell
}
}
return RequestsCell()
}
我的骑手应用(超级克隆)中的反向地理编码位置是:
func geoCode(location : CLLocation!) {
/* Only one reverse geocoding can be in progress at a time so we need to cancel existing
one if we are getting location updates */
geoCoder.cancelGeocode()
geoCoder.reverseGeocodeLocation(location, completionHandler: { (data, error) -> Void in
guard let placeMarks = data as [CLPlacemark]! else {
return
}
let loc: CLPlacemark = placeMarks[0]
let addressDict : [NSString: NSObject] = loc.addressDictionary as! [NSString: NSObject]
let addrList = addressDict["FormattedAddressLines"] as! [String]
let address = addrList.joined(separator: ", ")
print(addrList)
self.address.text = address
self.previousAddress = address
})
}
从另一个文件配置单元格:
class RequestsCell: UITableViewCell {
@IBOutlet weak var longitudeLabel: UILabel!
@IBOutlet weak var latitudeLabel: UILabel!
@IBOutlet weak var usernameLabel: UILabel!
func configureCell(requests: Requests) {
self.longitudeLabel.text = "\(requests.longitude)"
self.latitudeLabel.text = "\(requests.latitude)"
self.usernameLabel.text = "\(requests.usersname)"
}
} // 类 RequestsCell
【问题讨论】:
标签: uitableview swift3 ios10 reversegeocodelocation