我使用 MKLocalSearchCompleter 搜索地点并在选择 tableView 单元格时优化结果。When a MKLocalSearchCompletion is selected and MKLocalSearch.Request() is started, I get these Errors (example selects Los Angeles): According to my research this is a very rare problem?!
- [SearchAttribution] 未找到 org.volunteermatch ...(+4 个其他域)的匹配属性源
- 从 geod 加载标识符 org.volunteermatch 的属性信息时出错:错误域 = GEOErrorDomain 代码 = -8“未找到 org.volunteermatch 的匹配属性源” UserInfo={NSDebugDescription=未找到 org.volunteermatch 的匹配属性源} ...( +4 个其他域)
这些是 TableViewController 中的实例变量:
var searchCompleter = MKLocalSearchCompleter()
var searchResults = [MKLocalSearchCompletion]()
每次更改搜索词时都会运行此代码:
searchCompleter.queryFragment = text
searchCompleter.resultTypes = .address
searchCompleter.region = region
在 tableView ... didSelectRowAt ... 中执行此代码:
let selectedItem = searchResults[indexPath.row]
let searchRequest = MKLocalSearch.Request()
searchRequest.naturalLanguageQuery = selectedItem.title
searchRequest.resultTypes = .address
let search = MKLocalSearch(request: searchRequest)
search.start { (response, error) in
guard let coordinate = response?.mapItems[0].placemark.coordinate else {
return
}
// send to mainVC
self.delegate?.userSelectedPlace(coordinate: coordinate)
}
Xcode 12.4、iOS 14.4 模拟器