【问题标题】:GMSAutocompleteViewController get complete addressGMSAutocompleteViewController 获取完整地址
【发布时间】:2017-05-15 11:55:45
【问题描述】:

我使用 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 获取城市、国家/地区。但是我需要街道和街道号码的单独结果,以防万一。我尝试使用 thoroughfare 和 addressLine1, addressLine2 但没有结果,它们返回街道和街道号码的组合,我没有模式来拆分它。

获取方式方便吗?

【问题讨论】:

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


    【解决方案1】:

    要获取完整的地址字符串,请使用

    place.formattedAddress

    要获取地址中的每个字段,使用 addressComponents 数组。

    place.addressComponents

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 1970-01-01
      • 2012-06-04
      • 2011-12-09
      • 1970-01-01
      • 2010-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多