0

I am using mapkit to show locations, for search location, when the user type the location that location showed in mapkit. implemented custom search with autofilled locations, all are working fine. but when I click the some locations name in tableview it is showing

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)")

when I select any location I have to show location on mapkit

Bhavesh Nayi
  • 3,626
  • 1
  • 27
  • 42
naga
  • 397
  • 2
  • 12
  • 26

1 Answers1

0

Have a look at this answer, kCLErrorDomain Code=8 "The operation couldn’t be completed.

Sometimes, there are some elements in an address that do refer to precision for location in a building, and this will interfere with the matching of the actual location without that precision.

For example:

13 BOULEVARD DE LA LIBERTE, 35000 RENNES, FR is not recognized

and lead to a code=8 error, but if you use France instead of FR, you obtain your expected result.

13 BOULEVARD DE LA LIBERTE, 35000 RENNES, France is recognized

Vaseltior
  • 1,226
  • 15
  • 27