快速放置自动完成

时间:2021-03-24 11:52:09

标签: ios swift

This is the output I want

我想使用 Swift 将谷歌地点自动完成添加到 Xcode,这样用户就可以搜索城市并按 Enter,应用程序应该在 textField 上显示该城市。

这是我的代码

 @IBAction func onClickTf(_ sender: Any) {
        setLocationTf.resignFirstResponder()
        let acController = GMSAutocompleteViewController()
        acController.delegate = self
        present(acController, animated: true, completion: nil)
       
    }
    @IBAction func onClickBack(_ sender: Any) {
        self.navigationController?.popViewController(animated: true)
    }
    

}
extension SetLocationViewController: GMSAutocompleteViewControllerDelegate {
    func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
        // Get the place name from 'GMSAutocompleteViewController'
        // Then display the name in textField
        setLocationTf.text = place.name
        // Dismiss the GMSAutocompleteViewController when something is selected
        dismiss(animated: true, completion: nil)
    }
    func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
        // Handle the error
        print("Error: ", error.localizedDescription)
    }
    func wasCancelled(_ viewController: GMSAutocompleteViewController) {
        // Dismiss when the user canceled the action
        dismiss(animated: true, completion: nil)
    }
}

我得到了错误 enter image description here

谁能帮帮我

0 个答案:

没有答案