如何限制 Google 个地点自动完成不包含地址?

How to limit Google Places Autocomplete to not include Address?

如何限制 Google 地方自动完成不包括地址?我目前有我的设置

class FilterVC: UIViewController, GMSAutocompleteViewControllerDelegate {

// MARK: SEARCH BAR

@IBAction func searchBarAction(_ sender: Any) {
    let autocompleteController = GMSAutocompleteViewController()
    autocompleteController.delegate = self
    placeAutocomplete(resultsViewController: autocompleteController)
    UINavigationBar.appearance().barTintColor = UIColor.white
    UINavigationBar.appearance().tintColor = UIColor.hiGreyishBrownTwo
    UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [NSAttributedStringKey.foregroundColor.rawValue: UIColor.hiGreyishBrownTwo]
    present(autocompleteController, animated: true, completion: nil)
}
func placeAutocomplete(resultsViewController: GMSAutocompleteViewController) {
    var placeClient = GMSPlacesClient()
    let filter = GMSAutocompleteFilter()
    filter.type = .city
    filter.country = "USA"
    resultsViewController.autocompleteFilter = filter

    func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
        DataService.instance.place = place
        FillAddress(place: place)
        fillAddressForm()

        print(DataService.instance._address_line1)
         print(DataService.instance._city)
         print(DataService.instance._postalCode)
         print(DataService.instance._state)
         print(DataService.instance._country)
        DataService.instance.addressLabel = place.formattedAddress
        dismiss(animated: true, completion: nil)
}

func wasCancelled(_ viewController: GMSAutocompleteViewController) {
    dismiss(animated: true, completion: nil)
}
func viewController(_ viewController: GMSAutocompleteViewController, didFailAutocompleteWithError error: Error) {
    print("ERROR \(error) Autocomplete")
}

我尝试使用 GMSAutocompleteFilter 将我的结果限制为仅包括州城市、邮政编码、国家/地区。我不想在自动完成控制器中显示地址。当我这样做时,它只显示国家和城市,我无法输入邮政编码。我将如何提供它?我不太确定我遗漏了什么或下一步要做什么。任何建议将不胜感激。

因为我找到了解决方案,所以我打算取消它,但以防万一有人遇到类似问题,一个非常简单的解决方法是将过滤器类型设置为区域。

func placeAutocomplete(resultsViewController: GMSAutocompleteViewController) {
    var placeClient = GMSPlacesClient()
    let filter = GMSAutocompleteFilter()
    filter.country = "USA"
    filter.type = .region

    resultsViewController.autocompleteFilter = filter 

这会将搜索限制为不包括地址。在尝试 .city 时,这消除了很多。希望这对将来的人有所帮助。