How can I reverse geocode locations in each tableview row cell?
I have a table view controller where each uber request comes in as latitude and longitude. How can I convert each coordinate to actual address in a tableviewcontroller?
The code below in cellForRowAt is:
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()
}
Reverse Geocode location in my rider app (uber-clone) is:
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
})
}
Configure cell from another file:
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
You should do this in:
method.