I had the implementation of place auto completion using GMSAutocompleteResultsViewController was working fine so far. But when I updated the sdk to 3.0.2 stopped working. If I revert to version 2.7.0 start working.
I have gone through the migrationguide not getting what I am missing. I checked the examples didn't observe any changes. Would anyone point me in the right direction to make it work again?
class PlaceAutoCompleteController: BaseViewController {
    //MARK: - Property declaration
    private var resultsViewController = GMSAutocompleteResultsViewController()
    private lazy var searchController = UISearchController(searchResultsController: resultsViewController)
    private var viewModel: PlaceTypeAheadViewModel
    var storeSelectionDelegate: StoreSelectionDelegate?
    //MARK: - Life cycle
    init(withViewModel aviewModel: PlaceTypeAheadViewModel) {
        viewModel = aviewModel
        super.init()
    }
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        setupProperties()
    }
}
//MARK: - Property setup
extension PlaceAutoCompleteController {
    /// Setting up view default properties
    func setupProperties() {
        resultsViewController.view.backgroundColor = UIColor.white
        resultsViewController.tableCellBackgroundColor = .white
        resultsViewController.delegate = self
        // Specify the place data types to return.
//        let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue) |
//            UInt(GMSPlaceField.placeID.rawValue))!
//        resultsViewController.placeFields = fields
        let filter      = GMSAutocompleteFilter()
        //suitable filter type
        filter.type     = .establishment
        filter.country  = viewModel.getCountryId()
        resultsViewController.autocompleteFilter = filter
        searchController.searchResultsUpdater = resultsViewController
        // Put the search bar in the navigation bar.
        searchController.searchBar.sizeToFit()
        searchController.searchBar.placeholder = "Search places"
        let searchBgView = UIView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: 44))
        searchBgView.addSubview(searchController.searchBar)
        view.addSubview(searchBgView)
        // Prevent the navigation bar from being hidden when searching.
        searchController.hidesNavigationBarDuringPresentation = false
        // This makes the view area include the nav bar even though it is opaque.
        // Adjust the view placement down.
        extendedLayoutIncludesOpaqueBars = false
        edgesForExtendedLayout = []
    }
}
// Handle the user's selection.
extension PlaceAutoCompleteController: GMSAutocompleteResultsViewControllerDelegate {
    func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
                           didAutocompleteWith place: GMSPlace) {
        searchController.isActive = false
        AppManager.setPlace(withPlaceId: place.placeID ?? "" , name: place.name ?? "" , latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
        openStoreSelection()
    }
    func resultsController(_ resultsController: GMSAutocompleteResultsViewController,
                           didFailAutocompleteWithError error: Error){
        // TODO: handle the error.
        print("Error: ", error.localizedDescription)
    }
    // Turn the network activity indicator on and off again.
    func didRequestAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
        UIApplication.shared.isNetworkActivityIndicatorVisible = true
    }
    func didUpdateAutocompletePredictions(_ viewController: GMSAutocompleteViewController) {
        UIApplication.shared.isNetworkActivityIndicatorVisible = false
    }
    /// Open store selection screen with selected country
    func openStoreSelection() {
        navigateToStoreSelection()
    }
}
Thanks in advance.
In your Google Cloud project:


If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With