GoogleMaps Places swift 2,放置搜索框

时间:2015-10-28 18:20:08

标签: google-maps swift2 xcode7

我正在尝试创建一个自动完成的Google地方搜索框,我在googlemaps文档中搜索下面的代码,但是xcode在行标记了我的错误

     let place = placeLicklihoodList.likelihoods.first?.place

类型的价值' AnyObject'没有会员'地点'

           var placesClient: GMSPlacesClient?

    @IBOutlet var nameLabel: UILabel!
    @IBOutlet var addressLabel: UILabel!

    @IBAction func getCurrentPlace(sender: AnyObject) {
        placesClient?.currentPlaceWithCallback({ (placeLikelihoodList: GMSPlaceLikelihoodList?, error: NSError?) -> Void in
            if let error = error {
                print("Pick Place error: \(error.localizedDescription)")
                return
            }

            self.nameLabel.text = "No current place"
            self.addressLabel.text = ""

            if let placeLicklihoodList = placeLikelihoodList {
                let place = placeLicklihoodList.likelihoods.first?.place
                if let place = place
                {
                    self.nameLabel.text = place.name
                    self.addressLabel.text = "\n".join(place.formattedAddress.componentsSeparatedByString(", "))
                }
            }
        })
    }



          override func viewDidLoad() {
             placesClient = GMSPlacesClient()

    }

我一直在搜索自动完成谷歌搜索框的教程,但没有找到工作

1 个答案:

答案 0 :(得分:0)

placesClient?.currentPlaceWithCallback({
        (placeLikelihoodList: GMSPlaceLikelihoodList?, error: NSError?) -> Void in
        if let error = error {
            print("Pick Place error: \(error.localizedDescription)")
            return
        }
        if let placeLicklihoodList = placeLikelihoodList {

            let  place = placeLicklihoodList.likelihoods.first as! GMSPlaceLikelihood
            if let place : GMSPlaceLikelihood = place {
                print(place.place.formattedAddress)
            }
        }
    })