title: Getting error when using Google place api in swift
body: <p>I am using google place api to get location in my swift application. In my app when i am going to place api screen by clicking on the textfield present inside the cell of my tableview it is working fine. But when i am using  the same code to show the  place api screen by clicking on the textfield present inside the uiview, after selecting any place it is comming back to the previous screen, but once again the place api screen opening automatically.  i have added my code, can anyonce see it and let me know the solution?</p>
  <pre><code>import GooglePlaces
  
  class AddPatientViewController: UIViewController{
     
      //MARK:- Properties
      @IBOutlet weak var location_TextField: UITextField!
    
      
      //MARK:- Variables
      
      var locationManager = CLLocationManager()
      var mAppDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate;
      
      
      //MARK:- LifeCycles Methods
      override func viewDidLoad() {
          super.viewDidLoad()
          
          setDelegate()
       
          
      }
  
      
      
      
      //MARK:- Helpers
     
      private func setDelegate(){
         
          location_TextField.delegate = self 
         
    }
     
      
     
      
      //MARK: - getLocation
      
      func getCurrentLatLongFromCLlocation() {
          
          locationManager.desiredAccuracy = kCLLocationAccuracyBest
          self.locationManager.requestWhenInUseAuthorization()
          
          
          if CLLocationManager.locationServicesEnabled() {
              switch CLLocationManager.authorizationStatus() {
              case .notDetermined, .restricted, .denied:
                  print(&quot;No access&quot;)
                  getPermissionAgain()
              case .authorizedAlways, .authorizedWhenInUse:
                  print(&quot;Access&quot;)
                  if let coordinateValue = locationManager.location?.coordinate {
                      
                      mAppDelegate.cordinateVal = coordinateValue
                      self.getPlaceDataUsingLocation()
                  }
              @unknown default:
                  getPermissionAgain()
              }
          } else {
              print(&quot;Location services are not enabled&quot;)
              getPermissionAgain()
          }
          
          
      }
      
      func getPermissionAgain(){
          
          let alert = UIAlertController(title: &quot;Simplr&quot;, message: &quot;Required location permission to set your search location&quot;, preferredStyle: .alert)
          let okayAction = UIAlertAction(title: &quot;Dismiss&quot;, style: .default, handler: nil)
          let settingsAction = UIAlertAction(title: &quot;Settings&quot;, style: .default) { (action) in
              if let appSettings = URL(string: UIApplication.openSettingsURLString) {
                  if #available(iOS 10.0, *) {
                      UIApplication.shared.open(appSettings, options: [:], completionHandler: { (enabled) in
                          DispatchQueue.main.async {
                              
                              //UIApplication.shared.registerForRemoteNotifications()
                              
                          }
                          
                      })
                  } else {
                      // Fallback on earlier versions
                  }
              }
          }
          alert.addAction(okayAction)
          alert.addAction(settingsAction)
          present(alert, animated: false, completion: nil)
          
      }
      
      
      func getPlaceDataUsingLocation(){
          
          DispatchQueue.global().async {
              
              // Specify the place data types to return.
              let placesClient = GMSPlacesClient.init()
              
              let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue) |
                                                          UInt(GMSPlaceField.placeID.rawValue) | UInt(GMSPlaceField.coordinate.rawValue) | UInt(GMSPlaceField.formattedAddress.rawValue))
              
              placesClient.currentPlace { (list, error) in
                  
                  if let error = error {
                      print(&quot;An error occurred: \(error.localizedDescription)&quot;)
                      return
                  }
                  
                  if let placeLikelihoodList = list?.likelihoods {
                      for likelihood in placeLikelihoodList {
                          let place = likelihood.place
                          print(&quot;\n\n&quot;)
                          print(&quot;Current Place name \(String(describing: place.name)) at likelihood \(likelihood.likelihood)&quot;)
                          print(&quot;Current PlaceID \(String(describing: place.placeID))&quot;)
                          print(&quot;Formatted Address: \(String(describing: place.formattedAddress))&quot;)
                          //                    print(&quot;Fields: \(place.)&quot;)
                          print(&quot;\nAddress Component: \(String(describing: place.addressComponents))\n&quot;)
                          print(&quot;Type: \(String(describing: place.types))&quot;)
                          
                      }
                  }
                  
                  
              }
              
              
          }
          
          
      }
     
  }
  
  
  
  //MARK: - UITextfield Delegate Methods
  
  
      func textFieldShouldBeginEditing(_ textField: UITextField) -&gt; Bool{
        
          if textField == location_TextField{
              let autocompleteController = GMSAutocompleteViewController()
              autocompleteController.delegate = self
  //            autocompleteController.primaryTextColor = UIColor(hex: &quot;#4C2B6D&quot;)
  //            autocompleteController.secondaryTextColor = UIColor(hex: &quot;#4C2B6D&quot;)
              
              // Specify the place data types to return.
              let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue) |
                  UInt(GMSPlaceField.placeID.rawValue) | UInt(GMSPlaceField.coordinate.rawValue) |
                  UInt(GMSPlaceField.formattedAddress.rawValue) | UInt(GMSPlaceField.addressComponents.rawValue))
              
              autocompleteController.placeFields = fields
              autocompleteController.navigationController?.navigationBar.barTintColor = .blue
              autocompleteController.navigationController?.navigationBar.prefersLargeTitles = true
              // Specify a filter.
              let filter = GMSAutocompleteFilter()
              filter.type = .geocode
              autocompleteController.autocompleteFilter = filter
              
              // Display the autocomplete view controller.
              autocompleteController.modalPresentationStyle = .fullScreen
              present(autocompleteController, animated: true, completion: nil)
          }
          return true
      }
      
     
  }
  
  //MARK: - GMSAutocompleteViewControllerDelegate
  
  @available(iOS 13.0, *)
  extension AddPatientViewController: GMSAutocompleteViewControllerDelegate {
      
      // Handle the user's selection.
      func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
  
          print(&quot;selected place is \(getFormattedAddressFromAddressComponents(place: place))&quot;)
          location_TextField.text = getFormattedAddressFromAddressComponents(place: place)
          self.dismiss(animated: true)
      }
      
      func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
          // TODO: handle the error.
          print(&quot;Error: &quot;, error.localizedDescription)
      }
      
      // User canceled the operation.
      func wasCancelled(_ viewController: GMSAutocompleteViewController) {
          self.dismiss(animated: true)
      }
      
      // 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
      }
      
      func getFormattedAddressFromAddressComponents(place: GMSPlace) -&gt; String{
          
          var neighborhood = &quot;&quot;
          var locality = &quot;&quot;
          var sublocality = &quot;&quot;
          var administrative_area_level_1 = &quot;&quot;
          
          var formatedAddress = &quot;&quot;
         
  
          if let addressComponents : Array&lt;GMSAddressComponent&gt; = place.addressComponents{
              print(addressComponents)
              
              for component in addressComponents{
                  
                  if component.types.contains(&quot;administrative_area_level_1&quot;){
                      
                      if let shortName = component.shortName{
                          
                          administrative_area_level_1 = shortName
  
                      }
                      
                  }
                  else if component.types.contains(&quot;neighborhood&quot;)
                  {
                      
                      neighborhood = component.name
                      
                  } else if component.types.contains(&quot;sublocality&quot;)
                  {
                      
                      sublocality = component.name
                          
                    
                  }else if component.types.contains(&quot;locality&quot;)
                  {
                      
                      locality = component.name
                  }
  
                  
              }
              
              var shouldAddComma = false
              
              if !isNullObject(anyObject: administrative_area_level_1){
  
                  shouldAddComma = true
                  
              }
  
              if !isNullObject(anyObject: neighborhood){
                  
                  formatedAddress = neighborhood
                  
              }else if !isNullObject(anyObject: sublocality){
                  
                  formatedAddress = sublocality
              }
              else if !isNullObject(anyObject: locality){
                  
                  formatedAddress = locality
              }
              
              
              if !isNullObject(anyObject: formatedAddress){
                  
                  if shouldAddComma{
                      
                      formatedAddress = &quot;\(formatedAddress),\(administrative_area_level_1)&quot;
                  }
              }
          }
          
          return formatedAddress
  
      }
      
  }
  
  </code></pre>