I'm trying to build a simple weather app and I'm stuck when trying to implement the search city function. I managed to implement the search function to return a list of CLPlacemarks, however, this includes a lot of points of interest (e.g. restaurants, street names..) which make the results very messy. Is there a way to limit the results to only cities with that name? Here's the code I have:
func updateSearchResults(for searchController: UISearchController) {
var searchText = searchController.searchBar.text
request.naturalLanguageQuery = searchText
localSearch = MKLocalSearch(request: request)
localSearch?.start { (searchResponse, _) in
guard let items = searchResponse?.mapItems else {
return
}
self.placemarks = [CLPlacemark]()
for pm in items {
self.placemarks.append(pm.placemark)
}
}
}