1

I have trouble using MapKit in Swift 5. There is a natural search query I'm using. If I type in specific streets it only gives me one or less options, while some of the used street names are used in several towns nearby.

func updateSearchResults(for searchController: UISearchController) {
    guard let mapView = mapView,
        let searchBarText = searchController.searchBar.text else { return }
    let request = MKLocalSearch.Request()
    request.naturalLanguageQuery = searchBarText
    request.region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: 51.6039482, longitude: 7.2675932),
                                        span: MKCoordinateSpan(latitudeDelta: 15000, longitudeDelta: 15000))
    request.region = mapView.region

    let search = MKLocalSearch(request: request)
    search.start { response, error in
        guard let response = response else {
            print("Error: \(error?.localizedDescription ?? "Unknown error").")
            return
        }

        self.matchingItems = []
        for item in response.mapItems {
            self.matchingItems.append(item)
        }
        self.tableView.reloadData()
    }
}

The request also switches between towns, through the input. Every second letter it's town A, else its town B. Where am I wrong, what didn't I set up in this query?

MyJBMe
  • 2,226
  • 4
  • 15
  • 21

0 Answers0