错误值 Optional(Error Domain=kCLErrorDomain Code=8 "(null)")

问题描述 投票:0回答:1

我正在使用mapkit来显示位置,对于搜索位置,当用户输入该位置时,该位置就会显示在mapkit中。

Error Domain=kCLErrorDomain Code=8 "(null)"。

enter image description here ]

        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上显示位置。

ios swift mapkit
1个回答
0
投票

看看这个答案。kCLErrorDomain Code=8 "操作无法完成。

有时,地址中的一些元素确实是指建筑物中位置的精度,这将干扰没有该精度的实际位置的匹配。

比如说

13 BOULEVARD DE LA LIBERTE, 35000 RENNES, FR 不被识别

并导致 code=8 错误,但如果你使用 France 而不是 FR,你获得了你预期的结果。

13 BOULEVARD DE LA LIBERTE, 35000 RENNES, France 是公认的

© www.soinside.com 2019 - 2024. All rights reserved.