在我实现 google Places API(用于在我的 map 中搜索地点)之后,我想保存之前搜索(搜索和选择)的地点,并在他下次点击应用程序中的搜索栏时显示它。
喜欢前 3 个搜索(之前的搜索历史)。 我无法这样做,因为我使用 GMSAutocompleteResultsViewController 作为我的默认搜索结果 Controller 。这是我的代码。
_resultsViewController = [[GMSAutocompleteResultsViewController alloc] init];
_resultsViewController.delegate = self;
self.searchController = [[UISearchController alloc] initWithSearchResultsController:_resultsViewController];
self.searchController.searchResultsUpdater = _resultsViewController;
根据 Google Places API 文档:https://developers.google.com/places/ios-api/autocomplete 如何用之前搜索到的结果更新tableview(resultsViewController)
最佳答案
- (void)viewController:(GMSAutocompleteViewController *)viewController
didAutocompleteWithPlace:(GMSPlace *)place {
[self dismissViewControllerAnimated:YES completion:nil];
// Do something with the selected place.
NSLog(@"Place name %@", place.name);
NSLog(@"Place address %@", place.formattedAddress);
NSLog(@"Place attributions %@", place.attributions.string);
}
使用此委托(delegate)方法,您将获得选定的搜索地点并将此地点名称保存到您的数据库、squilite 或您想要的任何最佳位置。并使用您的数据库更新您的表格。
关于ios - 如何使用 Google Places Autocomplete API iOS 保存以前搜索的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40587158/