ios - 错误值可选(错误域=kCLErrorDomain 代码=8“(空)”)
问题描述
当用户键入该位置在 mapkit 中显示的位置时,我正在使用 mapkit 显示位置,用于搜索位置。使用自动填充位置实现了自定义搜索,一切正常。但是当我单击 tableview 中的某些位置名称时,它会显示
错误域=kCLErrorDomain 代码=8“(空)”。
var searchCompleter = MKLocalSearchCompleter()
var searchResults = [MKLocalSearchCompletion]()
func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
searchResults = completer.results
for searchresult in searchResults {
print("titlevalues",searchresult.title)
}
if (searchResults.count != 0) {
self.searchTableView.isHidden = false
} else {
self.searchTableView.isHidden = true
}
self.searchTableView.reloadData()
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: SelectLocationTableCell = tableView.dequeueReusableCell(withIdentifier: "SelectLocationTableCell") as! SelectLocationTableCell
let searchresult = searchResults[indexPath.row]
cell.titleLabel.text = searchresult.title
cell.descriptionLabel.text = searchresult.subtitle
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let searchresult = searchResults[indexPath.row]
self.setSelectMarkinAction(searchResult: searchresult)
self.searchTableView.isHidden = false
self.doneButton.isHidden = false
}
func getCoordinate( addressString : String,
completionHandler: @escaping(CLLocationCoordinate2D, NSError?) -> Void ) {
let geocoder = CLGeocoder()
geocoder.geocodeAddressString(addressString) { (placemarks, error) in
if error == nil {
if let placemark = placemarks?[0] {
let location = placemark.location!
completionHandler(location.coordinate, nil)
return
}
}
completionHandler(kCLLocationCoordinate2DInvalid, error as NSError?)
}
}
func setSelectMarkinAction(searchResult: MKLocalSearchCompletion) {
print("location address tile",searchResult.title)
getCoordinate(addressString: searchResult.title) { (location, error) in
if (error == nil) {
self.setMarkLocationInMap(searchResult: searchResult, location: location)
print("locationdata",location)
} else {
print("error values",error as Any)
}
}
}
This error am getting some of locations
location address tile Reva University
error values Optional(Error Domain=kCLErrorDomain Code=8 "(null)")
当我选择任何位置时,我必须在 mapkit 上显示位置
解决方案
看看这个答案, kCLErrorDomain Code=8 "操作无法完成。
有时,地址中的某些元素确实指的是建筑物中的位置精度,如果没有该精度,这将干扰实际位置的匹配。
例如:
13 BOULEVARD DE LA LIBERTE, 35000 RENNES, FR
不被认可
并导致code=8
错误,但如果您使用France
而不是FR
,您将获得预期的结果。
13 BOULEVARD DE LA LIBERTE, 35000 RENNES, France
被认可
推荐阅读
- java - Hibernate Save() - 'Save Method' save() 在事务之外工作是什么意思?
- javascript - 如何使用 ASP 经典从父窗口传递的查询字符串变量中填充弹出窗口的 HTML 输入字段
- c# - 如何为具有与内置单元格相同的布局指标的“UITableView”提供自定义“UITableCell”?
- wildfly - Hazelcast 需要作为现有集群中的客户端而不是成员连接
- postgresql - Postgresql 使用 docker-compose 成功部署,但未在 docker stack deploy
- c# - Windows 窗体在启动时尴尬地“调整大小”
- ruby - 如果是 env,则在 Vagrantfile 中设置默认值。变量未设置
- java - Maven 问题更新和依赖项
- laravel - 使用 mongodb 重置 Laravel 密码
- python - Python:创建网络的最佳方式?