Ios 通过GoogleApi获取搜索的位置以填写tableview
我尝试了GMSPlacesClient,但无法获得正确格式的结果以在tableView中填充它们 在那之后,我使用了取款机,但我没有帮助我Ios 通过GoogleApi获取搜索的位置以填写tableview,ios,swift,google-places,gmsplace,Ios,Swift,Google Places,Gmsplace,我尝试了GMSPlacesClient,但无法获得正确格式的结果以在tableView中填充它们 在那之后,我使用了取款机,但我没有帮助我 extension SearchViewController: GMSAutocompleteFetcherDelegate { func didAutocomplete(with predictions: [GMSAutocompletePrediction]) { let resultsStr = NSMutableString() fo
extension SearchViewController: GMSAutocompleteFetcherDelegate {
func didAutocomplete(with predictions: [GMSAutocompletePrediction]) {
let resultsStr = NSMutableString()
for prediction in predictions {
resultsStr.appendFormat("%@\n", prediction.attributedPrimaryText)
}
print(resultsStr as String)
}
func didFailAutocompleteWithError(_ error: Error) {
print(error.localizedDescription)
}
}
我不知道我是否不明白它的用法。也许有人向我描述了如何使用GooglePlacesAPI在文本框中搜索地址,然后在tableView中显示结果
我的问题是一个搜索结果
获取部件代码:
var fetcher: GMSAutocompleteFetcher?
func placeAutocomplete(add:String) {
fetcher?.sourceTextHasChanged(add)
}
override func viewDidLoad() {
super.viewDidLoad()
tblView.delegate = self
tblView.dataSource = self
let filter = GMSAutocompleteFilter()
filter.type = .establishment
// Create the fetcher.
fetcher = GMSAutocompleteFetcher(bounds: nil, filter: filter)
fetcher?.delegate = self
}
搜索“Mex”的结果
应该对结果使用数组,而不是让resultsStr=NSMutableString()
并使用数据源作为数组填充表视图您需要使用
GMSAutocompleteFilter
filter进行调整以获得所需的结果。当前,您正在使用以下筛选器类型筛选结果:.restitution
,用于筛选/限制搜索结果。您可以考虑使用<代码> .nfulter < /C>或任何其他筛选器。
let filter = GMSAutocompleteFilter()
filter.type = .noFilter
参考enum GMSPlacesAutocompleteTypeFilter
,来源:gmsautompletefilter.h
public enum GMSPlacesAutocompleteTypeFilter : Int {
/**
* All results.
*/
case noFilter
/**
* Geeocoding results, as opposed to business results.
*/
case geocode
/**
* Geocoding results with a precise address.
*/
case address
/**
* Business results.
*/
case establishment
/**
* Results that match the following types:
* "locality",
* "sublocality"
* "postal_code",
* "country",
* "administrative_area_level_1",
* "administrative_area_level_2"
*/
case region
/**
* Results that match the following types:
* "locality",
* "administrative_area_level_3"
*/
case city
}
问题:1。您知道如何全面使用
UITableView
吗?2.您知道如何从任何API获取数据,比如使用Postman测试API吗?3.你试着理解谷歌的API文档了吗?我是一个不喜欢阅读的人,但谷歌的文档对我来说很容易理解,而且写得很好。是的,我知道如何使用UITableView并从API获取数据,这些不是我的问题。问题是我不能使用fetcher的结果,它与我的searchvar results=[GMSAutocompletePrediction]()//数组self.results=predictions//预测是func didsautocomplete的结果无关(使用预测:现在您可以显示结果数组中的数据为什么结果与我的搜索词无关try filter let filter=GMSAutocompleteFilter()filter.type=GMSPlacesAutocompleteTypeFilter.noFilter并将其作为参数传递给autocompleteQuery。)(谢谢,为什么结果是嵌套的和部分的?示例是搜索我,它在我的问题部分。如何显示完整语句?
let filter = GMSAutocompleteFilter()
filter.type = .noFilter
public enum GMSPlacesAutocompleteTypeFilter : Int {
/**
* All results.
*/
case noFilter
/**
* Geeocoding results, as opposed to business results.
*/
case geocode
/**
* Geocoding results with a precise address.
*/
case address
/**
* Business results.
*/
case establishment
/**
* Results that match the following types:
* "locality",
* "sublocality"
* "postal_code",
* "country",
* "administrative_area_level_1",
* "administrative_area_level_2"
*/
case region
/**
* Results that match the following types:
* "locality",
* "administrative_area_level_3"
*/
case city
}