ios - 如何使用 Google Places Autocomplete API iOS 保存以前搜索的结果

标签 ios autocomplete google-places-api

在我实现 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/

相关文章:

iphone - 将 webview 中的照片保存到 ios 照片库

google-maps - 使用谷歌地图获取附近的地方

go - 多线程 HTTP 客户端请求的重构程序

python - 确定 GPS 坐标是否落在道路上

ios - 如何滚动到 UITextView 中的当前光标位置?

iphone - iOS开发: What are some reasons that [[self navigationController] viewControllers]; would return nil?

ios - 如何将 Swift 数组转换为字符串?

java - 无法在 Android 中使用 Volley 响应执行 AutoCompleteTextView

javascript - 使用 jquery 验证插件验证 Jquery 自动完成字段

java - 如何在 IntelliJ 中提出自定义自动完成建议?