GMSAutocompleteViewController获取完整地址

时间:2017-05-15 11:55:45

标签: ios swift google-maps geocoding reverse-geocoding

我正在使用GMSAutocompleteViewController让用户搜索地址。 在用户选择建议后,如何从GMSAutocompleteViewController获取地址详细信息? 我正在使用

func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {

获取UI控制器的结果。然后我反向地理编码以获得GMSAddress。代码是这样的:

GMSGeocoder().reverseGeocodeCoordinate(place.coordinate, completionHandler: { (response:GMSReverseGeocodeResponse?, err:Error?) in
...
let firstAddr:GMSAddress = (response?.firstResult())!

我能够从firstAddr获得城市,国家。但是我需要单独的街道和街道号码结果。我试图使用通途和addressLine1, addressLine2 ,但没有结果,他们返回街道和街道号码的组合,我没有分裂它的模式。

获取它是一种简单的方法吗?

1 个答案:

答案 0 :(得分:2)

要获取完整的地址字符串

  

place.formattedAddress

获取地址用户addressComponents数组中的每个字段

  

place.addressComponents

相关问题