作者:的发个地方 | 来源:互联网 | 2023-01-13 14:25
1> cldrr..:
我认为您不能将自己的位置和POI添加到MapKit,但是:
1)我建议您创建一个自己的枚举
class CustomSearchResult {
let title: String
...
}
enum SearchResultType {
case localSearchResult(result: MKLocalSearchCompletion)
case customResult(result: CustomSearchResult)
}
2)您将得到一系列结果:
var searchResults = [SearchResultType]()
3)在其中,completerDidUpdateResults
您可以将个人结果和MapKit结果添加到searchResults
数组中:
searchResults = completer.results.map {
SearchResultType.localSearchResult(result: $0) }
// Add here custom results
searchResults.append(SearchResultType.customResult(result:
CustomSearchResult(title: "test")))
4)..并且cellForRowAtIndexPath
您可以决定是否具有自定义或MapKit结果:
let searchResult = searchResults[indexPath.row]
switch searchResult {
case .customResult(let result):
cell.textLabel.text = result.title
case .localSearchResult(let result):
cell.textLabel.text = result.title
}