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

How to save previously searched results using Google Places Autocomplete API iOS

在我实施后,google Places API(用于在我的地图中搜索地点),我想保存之前搜索(搜索和选择)的地点并在他下次显示时展示点击应用程序中的搜索栏。

喜欢前 3 个搜索(以前搜索的历史记录)。 我无法这样做,因为我使用 GMSAutocompleteResultsViewController 作为我的默认搜索结果控制器。这是我的代码。

_resultsViewController = [[GMSAutocompleteResultsViewController alloc] init];
_resultsViewController.delegate = self;

self.searchController = [[UISearchController alloc] initWithSearchResultsController:_resultsViewController];
self.searchController.searchResultsUpdater = _resultsViewController;

根据 Google 地点 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);
}

使用此委托方法,您将获得选定的搜索地点并将此地点名称保存到您的数据库、squilite 或您想要的任何最佳位置。并使用您的数据库更新您的 table.

因为具有用户可以 select 最后 selected 地点的功能。如果可以使用数据库或者保存在 NSUserDefaults 中就好了。并在您的表视图中添加一个检查以获取用户默认值,如果找到则将其附加到数组的索引 0。