Reputation: 33
I'm using GMSAutocompleteViewController in order to let the user search for an address. How can I get address details from GMSAutocompleteViewController after the user choose a suggestion ? I'm using
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
to get the result of the UI controller. Then I'm reverse geocoding in order to get an GMSAddress. The code is like this:
GMSGeocoder().reverseGeocodeCoordinate(place.coordinate, completionHandler: { (response:GMSReverseGeocodeResponse?, err:Error?) in
...
let firstAddr:GMSAddress = (response?.firstResult())!
I was able to get city, country from firstAddr. But I need separate results for street and street number in case they are. I tried to use thoroughfare and addressLine1, addressLine2 but without result, they return a combination of street and street number and I don't have a patter to split it.
Is it an easy way to obtain it?
Upvotes: 1
Views: 1074
Reputation: 258
To get the complete address string use
place.formattedAddress
To get the each field in the address, using addressComponents array.
place.addressComponents
Upvotes: 2