8

Currently , it queries in every country, but I want it to only query in Singapore

I found a stackoverflow solution How to get country specific result with Google autocomplete place api ios sdk?, but couldn't figure out where do i put the code.

Here's the code, I use the full screen solution for autocomplete.

import UIKit
import GoogleMaps

class OnlyLocationViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
                // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    @IBAction func clickMe(sender: UIButton) {
        let autocompletecontroller = GMSAutocompleteViewController()
        autocompletecontroller.delegate = self
        self.presentViewController(autocompletecontroller, animated: true, completion: nil)


    }

}

extension OnlyLocationViewController: GMSAutocompleteViewControllerDelegate{

    func viewController(viewController: GMSAutocompleteViewController, didAutocompleteWithPlace place: GMSPlace) {
        print("Place name: ", place.name)
        print("Place address: ", place.formattedAddress)
        print("Place attributions: ", place.attributions)

        self.dismissViewControllerAnimated(true, completion: nil)
    }


    func viewController(viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: NSError) {
        // To handle error
        print(error)

    }
    func wasCancelled(viewController: GMSAutocompleteViewController) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }

    func didRequestAutocompletePredictions(viewController: GMSAutocompleteViewController) {
        UIApplication.sharedApplication().networkActivityIndicatorVisible = true
    }

    func didUpdateAutocompletePredictions(viewController: GMSAutocompleteViewController) {
        UIApplication.sharedApplication().networkActivityIndicatorVisible = false
    }


}

Where should I put the filter code?

Community
  • 1
  • 1
airsoftFreak
  • 1,450
  • 5
  • 34
  • 64
  • Does this answer your question? [How to get country specific result with Google autocomplete place api ios sdk?](https://stackoverflow.com/questions/31678607/how-to-get-country-specific-result-with-google-autocomplete-place-api-ios-sdk) – Sanman Apr 02 '20 at 07:46

1 Answers1

23

Try using this

@IBAction func clickMe(sender: UIButton) {
        let autocompletecontroller = GMSAutocompleteViewController()
        autocompletecontroller.delegate = self
        let filter = GMSAutocompleteFilter()
        filter.type = .Establishment  //suitable filter type
        filter.country = "SG"  //appropriate country code
        autocompletecontroller.autocompleteFilter = filter
        self.presentViewController(autocompletecontroller, animated: true, completion: nil)
    }
geocodezip
  • 158,664
  • 13
  • 220
  • 245
Sanman
  • 1,158
  • 11
  • 23
  • for more information about this you can follow, https://developers.google.com/places/ios-sdk/autocomplete#filter_results_by_country. And https://stackoverflow.com/questions/31678607/how-to-get-country-specific-result-with-google-autocomplete-place-api-ios-sdk is a good discussion about this topic. – Wimukthi Rajapaksha Mar 31 '20 at 14:28