获取GoogleApi搜索的位置以填写表格
我尝试了GMSPlacesClient,但无法以正确格式在tableView中填充结果。获取GoogleApi搜索的位置以填写表格
之后,我用Fetcher,但我帮不了我。
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)
}
}
我不知道我是否不明白它的用法。有人可能会描述我如何使用Google Places API在textBox中搜索地址,然后在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
}
结果搜索 “墨西哥”
> Me{
GMSAutocompleteMatch = "<GMSAutocompleteMatchFragment: 0x60800043db60>";
}rcado de La Boqueria, La Rambla, Barcelona, Spain{
}*
Me{
GMSAutocompleteMatch = "<GMSAutocompleteMatchFragment:
0x60800043db60>";
}rcado San Anton, Calle de Augusto Figueroa, Madrid, Spain{
}*
Me{
GMSAutocompleteMatch = "<GMSAutocompleteMatchFragment: 0x60800043db60>";
}nlyn Mall, Atterbury Road, Pretoria, South Africa{
}*
Me{
GMSAutocompleteMatch = "<GMSAutocompleteMatchFragment:
0x60800043db60>";
}ga Mall, Bulevardul Pierre de Coubertin, Bucharest, Romania{
}*
Me{
GMSAutocompleteMatch = "<GMSAutocompleteMatchFragment:
0x60800043db60>";
}rcado de San Ildefonso, Calle de Fuencarral, Madrid, Spain{
}*
打印代码:
for q in predictions1
{
print ("\(q.attributedFullText)*")
}
英语新HOULD使用阵列结果的代替让resultsStr =的NSMutableString()
并填充表视图与数据源作为阵列
让我有一些代码片断如果u前 –
VAR的结果= [GMSAutocompletePrediction]()//阵列 self.results =预测//做预测从FUNC didAutocomplete结果(预测: 现在你可以从显示效果阵列 – Sandy
数据为什么结果不与我的搜索词 –
您需要使用GMSAutocompleteFilter
滤波器来调整以获得期望的结果。目前,您正在使用过滤器类型筛选结果:.establishment
,它过滤/限制搜索结果。您可以考虑使用.noFilter
或任何其他过滤器。
let filter = GMSAutocompleteFilter()
filter.type = .noFilter
参考enum GMSPlacesAutocompleteTypeFilter
,来源:
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.您是否尝试了解Google的API文档?我是一个不喜欢阅读的人,但Google的文档很容易理解,写得很好。 – Glenn
是的,我知道如何使用UITableView并从API中获取数据/他们不是我的问题。问题是,我不能使用提取程序的结果,这不是关系到我的搜索 –