tableviewcontroller 中的反向地理编码位置

reverse geocode location in a tableviewcontroller

如何在每个 table 视图行单元格中反转地理编码位置?

我有一个 table 视图控制器,其中每个超级请求都以纬度和经度的形式出现。如何将每个坐标转换为 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()
}

我的骑手应用程序 (uber-clone) 中的反向地理编码位置是:

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)"
}

} // class RequestsCell

您应该在以下时间执行此操作:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{

}

方法。