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

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

    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("All component type \(component.type)")
    
           if component.type == "locality"{
                print("This is city name \(component.name)")
            }
        })
        print(values)
    

提交回复
热议问题