How to extract street, city, etc. from GMSPlace Address Components

后端 未结 10 1897
栀梦
栀梦 2021-02-20 02:51

I\'m using Google Places API for iOS and can successfully retrieve nearby places and present the address as a string. What I\'m trying to do is extract address components such

10条回答
  •  再見小時候
    2021-02-20 03:40

    For the latest Google Places API (July 2019) this is what could help you. Actually, Google now putting a couple of types for each element. So the "type" is now deprecated and "types" is new filed.

    You can do something like this:

     for addressComponent in (self.mySelectedPlace?.addressComponents)! {
                for type in (addressComponent.types){
    
                    switch(type){
                        case "country":
                            var country = addressComponent.name
    
                        case "postal_code":
                             var postCode = addressComponent.name
    
                    default:
                        break
                    }
    
                }
            }
    

提交回复
热议问题