【问题标题】:GMSPlace Auto Complete Always return same Place coordinateGMSPlace 自动完成总是返回相同的地点坐标
【发布时间】:2021-11-11 09:02:03
【问题描述】:

自动自动完成的返回总是给出相同的值。

  func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
      print("Place name: \(place.name)")
      print("Place coordinate: \(place.coordinate)")
    dismiss(animated: true, completion: nil)
  }

这是我总是得到的值:

CLLocationCoordinate2D(latitude: -180.0, longitude: -180.0)

这是我用来调用 searchViewController 获取地址的代码:

func showSearchViewController() {
    let autocompleteController = GMSAutocompleteViewController()
    autocompleteController.delegate = self
    
    // Specify the place data types to return.
    let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue))
    autocompleteController.placeFields = fields
    
    // Specify a filter.
    let filter = GMSAutocompleteFilter()
    filter.type = .address
    autocompleteController.autocompleteFilter = filter
    
    // Display the autocomplete view controller.
    present(autocompleteController, animated: true, completion: nil)
}

【问题讨论】:

    标签: ios swift google-places-api googleplacesautocomplete


    【解决方案1】:

    要解决此问题,您需要在字段GMSPlaceField 中指定您想要的数据。

    例如,如果您想要输入名称和坐标:

    let fields: GMSPlaceField = GMSPlaceField(rawValue: UInt(GMSPlaceField.name.rawValue) | UInt(GMSPlaceField.coordinate.rawValue))
    autocompleteController.placeFields = fields
    

    【讨论】:

      猜你喜欢
      • 2012-04-14
      • 2019-10-16
      • 2019-09-22
      • 2017-07-20
      • 1970-01-01
      • 2014-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多