添加评论[]与谷歌地方详细信息

时间:2018-01-12 11:15:23

标签: ios swift uitableview google-places-api swift4

关注Google API文档(https://developers.google.com/places/web-service/details)我试图在我的自定义表格视图单元格中首次添加带有Google地方详细信息的评论[],但它不起作用。我已经添加了其他参数,如网站和电话号码,两者都运作良好,但惠特评论我肯定做错了什么。这是我的自定义tableViewCell

private let authorKey = "author_name"
private let ratKey = "rating"
private let ctextKey = "text"


class MyTableViewCell: UITableViewCell {

@IBOutlet weak var myCommentsText: UILabel!
var place: EClass?


  func update(place:EClass) {
        self.place = place
        myLabel.text = place.name
        myImage.image = UIImage(named: "foto_icon.png")
        if let url = place.photos?.first?.getPhotoURL(maxWidth: maxWidht) {
            myImage.af_setImage(withURL: url)
        }



        NearZone.PlaceDetails(place: place) { (place) in
            DispatchQueue.main.async {

            if let phoneNumber = place.details?["international_phone_number"] as? String {
                self.myLabel2.text = place.getDescription() + "\n\(phoneNumber)"
                }
            else {
                self.myLabel2.text = place.getDescription()
                }
            }

// THIS PART DOES NOT WORK
if let comments = place.details?["reviews[]"] as? [[String:Any]] {
               if let au = place.details?[authorKey] as? String, let ra = place.details?[ratKey] as? Float,
                let ct = place.details?[ctextKey] as? [String] {

                self.myCommentsText.text = "\(comments)"
                }
            }
        }
    }

,这是我的功能PlaceDetails

  static func PlaceDetails(place:EClass, completion: @escaping (EClass) -> Void) {

        guard place.details == nil else {
            completion(place)
            return
        }

        var params : [String : Any]
        params = [
            "key" : AppDelegate.googlePlacesAPIKey,
            "placeid" : place.placeId,
        ]

        Alamofire.request(googlePlaceDetailsHost, parameters: params, encoding: URLEncoding(destination: .queryString)).responseJSON { response in
            let value = response.result.value as? [String : Any]
            place.details = (value)?["result"] as? [String : Any]
            print(((value)?["result"] as? [String : Any] ?? [String : Any]()).debugDescription)
            completion(place)
        }
    }

有人可以帮我解决这个问题吗?

0 个答案:

没有答案