ios - 将 GMSAutocompleteViewController 设置为仅指定特定状态

标签 ios swift google-maps autocomplete

当我单击 GMSAutocompleteViewController 时,它应该只显示建议中的所有状态。我不想要这个领域的城市、国家或其他任何东西。那么这可能吗?

最佳答案

您无法直接过滤状态,Google Auto Complete API 提供了一些过滤器及其预定义的 ENUMS。

let autocompleteController = GMSAutocompleteViewController()
autocompleteController.delegate = self

// Set a filter to return only addresses.
let filter = GMSAutocompleteFilter()
filter.type = .address
autocompleteController.autocompleteFilter = filter

present(autocompleteController, animated: true, completion: nil)

GMSAutocompleteFilter.h : ENUMS description below

typedef NS_ENUM(NSInteger, GMSPlacesAutocompleteTypeFilter) {
  /**
   * All results.
   */
  kGMSPlacesAutocompleteTypeFilterNoFilter,
  /**
   * Geeocoding results, as opposed to business results.
   */
  kGMSPlacesAutocompleteTypeFilterGeocode,
  /**
   * Geocoding results with a precise address.
   */
  kGMSPlacesAutocompleteTypeFilterAddress,
  /**
   * Business results.
   */
  kGMSPlacesAutocompleteTypeFilterEstablishment,
  /**
   * Results that match the following types:
   * "locality",
   * "sublocality"
   * "postal_code",
   * "country",
   * "administrative_area_level_1",
   * "administrative_area_level_2"
   */
  kGMSPlacesAutocompleteTypeFilterRegion,
  /**
   * Results that match the following types:
   * "locality",
   * "administrative_area_level_3"
   */
  kGMSPlacesAutocompleteTypeFilterCity,
};

关于ios - 将 GMSAutocompleteViewController 设置为仅指定特定状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51705065/

相关文章:

xcode - TouchsBegin 不适用于多次触摸

java - 将折线添加到 map 错误失败解决: Ljava/time/ZonedDateTime

ios - SwiftUI TextField 最大长度

cocoa - 意外的 NSTextField 背景颜色,应该是透明的

ios - 为什么在尝试返回从 Parse.com 获取的 UIImage 时出现此错误?

ios - 照片和视频未保存在我的自定义相册中

ios - Google map 服务条款对 iOS 应用程序开发人员在实践中意味着什么?

Android : If markers are overlapping each other on the map, 然后触发最后一个隐藏的点击事件

ios - 为什么 Firebase 库没有导入到我的 iOS Swift 应用程序中?

objective-c - 隐藏 KeyWindow 以截取空白屏幕截图