2

I have setup the Google GMSAutocomplete like so:

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
}

and also implemented the delegates, UITextFieldDelegate, GMSAutocompleteTableDataSourceDelegate and it's working great. However, I would like to limit the search to locality, administrativeArea and country. e.g. I don't want it to search for 'Places'. let

I know there is the filter object; however, how do I apply it to my use? Any ideas?

filter = GMSAutocompleteFilter(), filter.type = GMSPlacesAutocompleteTypeFilter.City

oyalhi
  • 3,834
  • 4
  • 40
  • 45

2 Answers2

2

You can set the autocompleteFilter field of the GMSAutocompleteTableDataSource.

Jamie McCloskey
  • 379
  • 1
  • 2
  • Yes! Thank you. I was trying the 'filter' property with no luck. So much for NOT reading the docs. – oyalhi Jan 19 '16 at 22:34
0

Google auto complete api

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)")
  }
  }
 })
}
Bhoomi Jagani
  • 2,413
  • 18
  • 24
  • Your answer is to get place predictions programmatically. I am using the place api widget (top of the same page as your link) and would like to filter it with the widget. Any ideas? – oyalhi Jan 19 '16 at 22:10