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

后端 未结 10 1834
栀梦
栀梦 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:44

    Swift 4

        var keys = [String]()
        place.addressComponents?.forEach{keys.append($0.type)}
        var values = [String]()
        place.addressComponents?.forEach({ (component) in
            keys.forEach{ component.type == $0 ? values.append(component.name): nil}
        })
        print(values) 
    

提交回复
热议问题