MKLocalSearch does not return the expected result

I am creating an iOS application and I have a requirement to create a meeting similar to Calendar's Create Event default event.

I need to fill in the location field, which will indicate the location of the meeting, and I use MKLocalSearchRequest / MKLocalSearch.

But the output that I get is very different from what I get in the default Calendar application.

I would like to get a similar result from the Calendar application.

My question is: why am I getting great results from the Calendar app? and what I need to do to get a similar result in the Calendar application.

My code is pretty simple -

I have a view controller that has a table view and it implements UISearchResultsUpdating

to give the user a custom search string for text input and based on the fact that I am doing MKLocalSearch and returning the result.

func updateSearchResultsForSearchController(searchController: UISearchController) {
    locations_name.removeAll(keepCapacity: false)
    locations_title.removeAll(keepCapacity: false)

    var searchRequest = MKLocalSearchRequest()
    searchRequest.naturalLanguageQuery = searchController.searchBar.text

    var search = MKLocalSearch(request: searchRequest)
    search.startWithCompletionHandler { (response : MKLocalSearchResponse! , error : NSError!) -> Void in
        if response == nil {
            return
        }
        for result in response.mapItems {
            let item = result as! MKMapItem                
            self.locations_name.append(item.name)
            self.locations_title.append(item.placemark.title)

        }
        dispatch_async(dispatch_get_main_queue(), { () -> Void in
            self.tableView!.reloadData()
        })
    }

}

Here are the default images for finding the location of the application in the Calendar and search in the application.

enter image description here

enter image description here

+4
source share

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


All Articles