How to get a specific result for a country with autocomplete Google api ios sdk?

I use the method below to get the autocomplete result for the input string of the GMSPlacesClient class:

- (void)autocompleteQuery:(NSString *)query bounds:(GMSCoordinateBounds * GMS_NULLABLE_PTR)bounds filter:(GMSAutocompleteFilter * GMS_NULLABLE_PTR)filter callback:(GMSAutocompletePredictionsCallback)callback 

I tried to implement the borders in several ways, but none of them worked, I wonder if there is any standard way to get specific country results using GMSCoordinateBounds?

+4
source share
4 answers

You can get specific results by country using the autocomplete Google api iOS SDK. Just go to this link

 let filter = GMSAutocompleteFilter() filter.type = .Establishment filter.country = "UK" 

set the filter country to any country code you want. Then you will get only country-specific results for you.

You can get country codes from this link.

Hope this helps.

+20
source

In your google API url just add

  &components=country:sg here sg = country code for singapore. Append country code as per your requirement. 

The country must be transmitted as a two-digit country code, complying with ISO 3166-1 Alpha-2. You can refer the country code of different countries

+3
source

This work is for me.

 let placesClient = GMSPlacesClient() let filter = GMSAutocompleteFilter() filter.type = .Establishment filter.country = "SG" placesClient.autocompleteQuery(searchString, bounds: nil, filter: filter) { (results, error:NSError?) -> Void in self.resultsArray.removeAll() if let _ = results { for result in results!{ if let res: GMSAutocompletePrediction = result { // your code } } } } 
+2
source

It looks like the Google autocomplete API for iOS does not support filtering by country. GMSCoordinateBounds uses the NorthEast and southWest borders corresponding to a rectangular area defined by two angles.

It may be easier to use the Google Places API web service and filter using components=country: You can specify which country you want after country:

0
source

All Articles