1

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 ?

Nitish
  • 13,845
  • 28
  • 135
  • 263
  • add this print("Place attributions: \(place.attributions)") print("Longitude: \(place.coordinate.longitude)") print("Latitude: \(place.coordinate.latitude)") print("Address components: \(place.addressComponents)") and show the logs – Anbu.Karthik Mar 28 '17 at 11:25
  • @Anbu.Karthik : AddressComponents is an array. I have values in lat and long. Attributions is coming nil. – Nitish Mar 28 '17 at 11:30
  • may be ios those are given ike values – Anbu.Karthik Mar 28 '17 at 11:32
  • Is the placeID of the returned place the same on iOS and Android, or is it different? When you say "the result is displayed as", what do you mean. Do you mean the value of the formatted address? – AndrewR Mar 29 '17 at 00:14
  • @AndrewR : Found out one thing. In Android, GMSAutocompletePrediction class is used which returns the desired address on selecting search result. In iOS, I am using GMSAutocompleteViewController. I am wondering how may I use GMSAutocompletePrediction in GMSAutocompleteViewController so I may have this result. – Nitish Mar 29 '17 at 04:33
  • I think I see what you're after now. You want to access the secondary text displayed under the place name in the list (as seen in the screenshot above), right? This is possible. See my answer below. – AndrewR Mar 29 '17 at 23:15

1 Answers1

2

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;            
}  
AndrewR
  • 10,759
  • 10
  • 45
  • 56