Google place auto complete view controller in swift

write Following line in your pod file

pod 'GooglePlaces'

import file

import GooglePlaces

set google place key in appdelegate file

GMSPlacesClient.provideAPIKey(KEY_GMS_PROVIDER)

write following code for open google place search controller

func googleAddresses(){
        let autocompleteController = GMSAutocompleteViewController()
        autocompleteController.delegate = self
        UINavigationBar.appearance().tintColor = UIColor.black
        present(autocompleteController, animated: true, completion: nil)
        
        // changes the color of the sugested places
        autocompleteController.primaryTextColor = UIColor.black
        autocompleteController.secondaryTextColor = UIColor.gray
    }

Implement delegate method for google place controller (GMSAutocompleteViewController)

extension ViewController: GMSAutocompleteViewControllerDelegate {
    
    // Handle the user's selection.
    func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
        print("Place name: \(place.name)")
        var address: String = place.name
        var subaddress: String = ""
        strLocation = CLLocation(latitude: place.coordinate.latitude, longitude: place.coordinate.longitude)
       
        
        for component in place.addressComponents! {
            print(component.name)
            print(component.type)
            if component.type == "country" {
                subaddress = subaddress + ", " + component.name
            }else if component.type == "sublocality_level_1" {
                address = address + ", " + component.name
            }else if component.type == "locality" {
                address = address + ", " + component.name
            }else if component.type == "administrative_area_level_1" {
                subaddress = component.name
            }else if component.type == "postal_code" {
                address = address + " - " + component.name
            }else if component.type == "neighborhood" {
                address = address + ", " + component.name
            }
            print(address)
        }
        dismiss(animated: true, completion: nil)
    }
    
    func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) { 
        print("Error: ", error.localizedDescription)
    }
    
    // User canceled the operation.
    func wasCancelled(_ viewController: GMSAutocompleteViewController) {  
        dismiss(animated: true, completion: nil)
    }
    
    // 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
    }
}

How to Install pod framework in your Xcode project Click here