将GMSAutocompleteViewController设置为仅特定于状态



当我单击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描述

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,
};

相关内容

  • 没有找到相关文章