【问题标题】:reverse geocode location in a tableviewcontroller表格视图控制器中的反向地理编码位置
【发布时间】: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


    【解决方案1】:

    你应该这样做:

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

    方法。

    【讨论】:

    • 我为 cellForRowAt indexPath 添加了代码。我可以在哪里添加反向地理编码?
    • 您可能会从数组中获取纬度和经度。从特定索引中获取该值,然后转换
    • 我在骑手应用中添加了获取地址的方式。当我尝试输入地理编码一词时,我收到一条错误消息,指出它未声明。还添加了我的配置单元代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多