MKLocalSearch未返回预期结果

时间:2015-09-05 14:59:45

标签: ios mapkit mklocalsearch mklocalsearchrequest

我正在创建一个iOS应用,我需要创建约会,类似于默认日历应用的“创建活动”。

我必须填写一个位置字段,该字段将指定约会的位置,我正在使用MKLocalSearchRequest / MKLocalSearch。

但是,我得到的输出与我在默认日历应用程序上获得的输出完全不同。

我想获得日历应用程序的类似结果。

我的问题是 - 为什么我得到的结果与日历应用不同?我该怎么做才能得到与日历应用类似的结果。

我的代码非常简单 -

我有一个具有表视图的视图控制器,它实现了UISearchResultsUpdating

这样,用户可以在搜索栏中键入一些文本,然后根据该文本执行MKLocalSearch并返回结果。

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()
        })
    }

}

以下是默认日历应用位置搜索和我的应用搜索的图像。

enter image description here

enter image description here

0 个答案:

没有答案
相关问题