Searching for Place Names (City / City) Using MKLocalSearchCompleter

I am trying to create an autocomplete text box that should only display the city / city name.

So what I want to do is that when someone enters

Am he will show

Amsterdam
Amstelveen

Thus, it displays only the actual names of cities and nothing else. For this you do not need to take into account the surroundings, etc.

I already applied the filter, but this does not fix it.

 lazy var searchCompleter: MKLocalSearchCompleter = { let sC = MKLocalSearchCompleter() sC.delegate = self sC.filterType = .locationsOnly return sC }() func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) { self.searchSource = completer.results.map { $0.title } DispatchQueue.main.async { for result in self.searchSource! { print(result) } } } func completer(_ completer: MKLocalSearchCompleter, didFailWithError error: Error) { print(error.localizedDescription) } 

Does anyone know if it is possible to achieve what I want?

+5
source share

Source: https://habr.com/ru/post/1266903/


All Articles