Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
Change MKLocalPointsOfInterestRequest to MKLocalSearch.Request() and …
Browse files Browse the repository at this point in the history
…set searchText
  • Loading branch information
ABAYALI committed Jul 10, 2023
1 parent f565133 commit 3228cdb
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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([])
Expand All @@ -180,23 +183,20 @@ 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 {
completion([])
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 ?? [])
}
}
}

0 comments on commit 3228cdb

Please sign in to comment.