如何搜索Google Places
当我点击textField
并且想要显示低于textField
的结果。我正在使用Swift 3.0版本。请有人帮我当在Swift 3中单击textField时,在tableView上搜索Google Places?
1
A
回答
3
第一。然后你参考下面的代码。
斯威夫特
在AppDelegate中
import UIKit
import CoreData
import GoogleMaps
import GooglePlacePicker
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions
launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func setUpGoogleMaps()
return true
}
func setUpGoogleMaps() {
let googleMapsApiKey = "AIzaSyA-kiOBvrR9CNztqutwmKaSLyXIid93K0E"
GMSServices.provideAPIKey(googleMapsApiKey)
GMSPlacesClient.provideAPIKey("AIzaSyA-kiOBvrR9CNztqutwmKaSLyXIid93K0E")
}
在你的ViewController这是具有文本框
import UIKit
import GooglePlaces
import GoogleMaps
import GooglePlacePicker
class HotelVC: UIViewController, GMSMapViewDelegate, UITextFieldDelegate {
@IBOutlet weak var YourTextField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
self.YourTextField.delegate = self
}
func textFieldDidBeginEditing(_ textField: UITextField) {
let acController = GMSAutocompleteViewController()
acController.delegate = self
self.present(acController, animated: true, completion: nil)
}
}
extension viewController: GMSAutocompleteViewControllerDelegate {
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
print("Place name: \(place.name)")
print("Place address: \(place.formattedAddress ?? "null")")
self.YourTextField.text = place.formattedAddress
print("Place attributions: \(String(describing: place.attributions))")
self.dismiss(animated: true, completion: nil)
}
func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
// TODO: handle the error.
// print("Error: \(error.description)")
self.dismiss(animated: true, completion: nil)
}
// User canceled the operation.
func wasCancelled(_ viewController: GMSAutocompleteViewController) {
print("Autocomplete was cancelled.")
self.dismiss(animated: true, completion: nil)
}
}
0
您可以使用Google Places API。它可以帮助您轻松查找地点,也可以通过您的textField
激活它。
以下是你需要在你的项目安装GooglePlaces SDK链接https://developers.google.com/places/ios-api/autocomplete
相关问题
- 1. 创建搜索TextField字段在javafx tableview中搜索
- 2. 如何在Swift中打开搜索tableView
- 3. Google Places API地址搜索
- 4. Google Places API Swift
- 5. Google地图搜索框vs Google Places API
- 6. Google Places API搜索GLOBE中的PLace
- 7. 使用Places库在Google Maps V3上搜索现有点
- 8. swift 3 tableView在reloadData上没有更新()
- 9. 在Rails中单击图片时搜索
- 10. 在tableView中搜索单元问题
- 11. Google Places API - 附近搜索(Ionic 2)
- 12. Google Places API - radarSearch按名称搜索
- 13. Google Maps API Places Library搜索框
- 14. swift中的TableView 3
- 15. Android等价物Google Places REST API搜索
- 16. HttpWebResponse在Google Places API调用上超时
- 17. IOS:搜索栏在tableview中
- 18. Google Places API使用特定搜索字词数据搜索
- 19. 在textfield上双击
- 20. 如何从tableView中使用textfield搜索ipad中的数据
- 21. 当点击保存按钮并存储在字典中时,在tableview单元格中获取textfield?
- 22. Google Places API与AJAX搜索API和本地搜索控件
- 23. Google Maps API Places搜索获取搜索结果数量
- 24. Swift 3 - 在TableView中的numberOfRowsInSection后崩溃
- 25. 如何在Swift 3中限制TextField的双/单空格iOS
- 26. 当tableview被滚动时Textfield变空
- 27. 简单在目标c搜索tableview
- 28. 单击时搜索光标
- 29. Google在网站上搜索
- 30. XCode swift 3如果当前viewController在tableView中导航didSelect
感谢兄弟为我工作忘了投票@格雷戈里威尔逊Pullyattu – anuj