2016-12-29 49 views
0

如何反转每个tableview行单元格中的地理编码位置?在tableviewcontroller中反向地理编码位置

我有一个表视图控制器,其中每个超级请求作为经度和纬度进来。我怎样才能将每个坐标转换为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() 
} 
在我的骑手的应用程序(超级克隆)

反向地理编码位置是:

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)" 
} 
:从另一个文件

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

回答

1

你应该这样做的:

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

} 

方法。

+0

我添加了我为cellForRowAt indexPath设置的代码。我可以在哪里添加反向地理编码? – LizG

+0

你可能会从数组中获得经度和经度。从特定索引获取该值,然后转换 – SNarula

+0

我添加了如何在我的骑手应用中获取地址。当我尝试输入地理编码时,我收到一个错误,声明它是未声明的。还添加了我的配置单元代码。 – LizG