Search code examples
iosswiftgoogle-places-apigmsautocomplete

Google places - GMSAutocompleteViewController didAutocompleteWith full text


This is the delegate function in my viewController :

func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
        print("Place name: \(place.name)")
        print("Place address: \(place.formattedAddress)")

        dismiss(animated: true, completion: nil)
    }  

I searched for "Grav Skole" and selected the first option here :

enter image description here

Following are the logs :

Place name: Grav skole
Place address: "Hosleveien 24, 1358 Jar, Norway"

On Android, the result is displayed as "Grav skole, Hosleveien, Jar, Norway", which is the desired text and does not match with the iOS.
What am I missing ?


Solution

  • It sounds like you want to access the text of the predictions as they are displayed in the list by GMSAutocompleteViewController. You can do this by implementing the viewController:didSelectPrediction method of GMSAutocompleteViewControllerDelegate, which will be called when an item is selected.

    func viewController(_ viewController: GMSAutocompleteViewController, 
    didSelectPrediction prediction: GMSAutocompletePrediction) -> Bool {
        print("Primary: \(prediction.attributedPrimaryText)")
        print("Secondary: \(prediction.attributedSecondaryText)")
        return false;            
    }