Google自动完成API地址组件

时间:2017-03-17 14:34:33

标签: ios swift google-api

我在swift应用中使用google API来获取地址。我正在尝试检索我认为将在地址组件中的地址的城市。

当我使用下面的代码时,它会返回我不熟悉的代码:

Address components: Optional([<GMSAddressComponent: 0x17022b540>, <GMSAddressComponent: 0x170234b20>, <GMSAddressComponent: 0x17022b9a0>, <GMSAddressComponent: 0x17022cf80>, <GMSAddressComponent: 0x17022bb00>, <GMSAddressComponent: 0x170234f60>, <GMSAddressComponent: 0x1702346c0>, <GMSAddressComponent: 0x17022d580>])

我如何才能使其可读并从中检索城市名称?

任何帮助非常感谢

extension selectAddress: GMSAutocompleteViewControllerDelegate {

    // Handle the user's selection.
    func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {

        print("Address components: \(place.addressComponents)")

        dismiss(animated: true, completion: nil)

    }

1 个答案:

答案 0 :(得分:1)

想象它

让city = place.addressComponents?[2] .name