From 3228cdbad0c10fe31bba55ed3105566e6f1dd2eb Mon Sep 17 00:00:00 2001 From: Asma Date: Mon, 10 Jul 2023 11:11:02 +0100 Subject: [PATCH] Change MKLocalPointsOfInterestRequest to MKLocalSearch.Request() and set searchText --- .../Helpers/Search/SearchResultsUpdater.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/ios/GuideDogs/Code/Visual UI/Helpers/Search/SearchResultsUpdater.swift b/apps/ios/GuideDogs/Code/Visual UI/Helpers/Search/SearchResultsUpdater.swift index 9c5edf9a..03def906 100644 --- a/apps/ios/GuideDogs/Code/Visual UI/Helpers/Search/SearchResultsUpdater.swift +++ b/apps/ios/GuideDogs/Code/Visual UI/Helpers/Search/SearchResultsUpdater.swift @@ -172,6 +172,9 @@ extension SearchResultsUpdater: UISearchBarDelegate { func fetchPOIS(by searchText: String, latitudinalMeters: CLLocationDistance, longitudinalMeters: CLLocationDistance, completion: @escaping ([POI]?) -> Void) { var pois: [POI]? = [] + let request = MKLocalSearch.Request() + + request.naturalLanguageQuery = searchText guard let location = AppContext.shared.geolocationManager.location else { completion([]) @@ -180,8 +183,8 @@ extension SearchResultsUpdater: UISearchBarDelegate { let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude) let region = MKCoordinateRegion(center: center, latitudinalMeters: latitudinalMeters, longitudinalMeters: longitudinalMeters) - let request = MKLocalPointsOfInterestRequest(coordinateRegion: region) + request.region = region let search = MKLocalSearch(request: request) search.start { response, _ in guard let response = response else { @@ -189,14 +192,11 @@ extension SearchResultsUpdater: UISearchBarDelegate { return } for item in response.mapItems { - if let lat = item.placemark.location?.coordinate.latitude, - let long = item.placemark.location?.coordinate.longitude, - let name = item.name { - let poi = GenericLocation(lat: lat, lon: long, name:name) - pois?.append(poi) - } + let poi = GenericLocation(lat: (item.placemark.location?.coordinate.latitude)!, lon: (item.placemark.location?.coordinate.longitude)!, name: item.name!) + pois?.append(poi) + } - completion(pois) + completion(pois ?? []) } } }