我设置了Google GMSAutocomplete,如下所示:
private func setupAutocompleteWithTextFieldController() {
let kTextFieldTop: CGFloat = searchField.frame.origin.y
let kTextFieldHeight: CGFloat = 44.0
let kContentRectTop = kTextFieldTop + kTextFieldHeight
contentRect = CGRectMake(0, kContentRectTop, self.view.bounds.size.width, self.view.bounds.size.height - kTextFieldHeight)
searchField.autocorrectionType = .No
searchField.returnKeyType = .Done
searchField.clearButtonMode = .WhileEditing
searchField.addTarget(self, action: "searchFieldTextFieldEditingChanged:", forControlEvents: UIControlEvents.EditingChanged)
searchField.delegate = self
tableDataSource = GMSAutocompleteTableDataSource()
tableDataSource.delegate = self
resultsController = UITableViewController(style: UITableViewStyle.Plain)
resultsController.tableView.delegate = tableDataSource
resultsController.tableView.dataSource = tableDataSource
}
并且还实施了代理人UITextFieldDelegate
,GMSAutocompleteTableDataSourceDelegate
,并且工作得很好。但是,我想将搜索范围限制为locality,administrativeArea和country。例如我不想让它搜索“地方”。让
我知道有过滤器对象;但是,我如何将其应用于我的使用?有什么想法吗?
filter = GMSAutocompleteFilter()
,filter.type = GMSPlacesAutocompleteTypeFilter.City
答案 0 :(得分:2)
您可以设置GMSAutocompleteTableDataSource
的{{3}}字段。
答案 1 :(得分:0)
func placeAutocomplete() { //Call function from your search editing method
let filter = GMSAutocompleteFilter()
filter.type = GMSPlacesAutocompleteTypeFilter.City
//"YOUR_SEARCH_DATA" Ex. Sydney Oper
//Uou will get data for city sydney
placesClient?.autocompleteQuery("YOUR_SEARCH_DATA", bounds: nil, filter: filter, callback: { (results, error: NSError?) -> Void in
if let error = error {
println("Autocomplete error \(error)")
}
for result in results! {
if let result = result as? GMSAutocompletePrediction {
println("Result \(result.attributedFullText) with placeID \(result.placeID)")
}
}
})
}