Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. var searchCompleter = MKLocalSearchCompleter()
  2. var searchResults = [MKLocalSearchCompletion]()
  3.  
  4.  
  5. func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
  6. searchResults = completer.results
  7. for searchresult in searchResults {
  8. print("titlevalues",searchresult.title)
  9. }
  10. if (searchResults.count != 0) {
  11. self.searchTableView.isHidden = false
  12. } else {
  13. self.searchTableView.isHidden = true
  14. }
  15. self.searchTableView.reloadData()
  16. }
  17.  
  18.  
  19. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  20. let cell: SelectLocationTableCell = tableView.dequeueReusableCell(withIdentifier: "SelectLocationTableCell") as! SelectLocationTableCell
  21. let searchresult = searchResults[indexPath.row]
  22. cell.titleLabel.text = searchresult.title
  23. cell.descriptionLabel.text = searchresult.subtitle
  24. return cell
  25. }
  26. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  27. let searchresult = searchResults[indexPath.row]
  28. self.setSelectMarkinAction(searchResult: searchresult)
  29. self.searchTableView.isHidden = false
  30. self.doneButton.isHidden = false
  31. }
  32.  
  33. func getCoordinate( addressString : String,
  34. completionHandler: @escaping(CLLocationCoordinate2D, NSError?) -> Void ) {
  35. let geocoder = CLGeocoder()
  36. geocoder.geocodeAddressString(addressString) { (placemarks, error) in
  37. if error == nil {
  38. if let placemark = placemarks?[0] {
  39. let location = placemark.location!
  40. completionHandler(location.coordinate, nil)
  41. return
  42. }
  43. }
  44. completionHandler(kCLLocationCoordinate2DInvalid, error as NSError?)
  45. }
  46. }
  47.  
  48. func setSelectMarkinAction(searchResult: MKLocalSearchCompletion) {
  49. print("location address tile",searchResult.title)
  50. getCoordinate(addressString: searchResult.title) { (location, error) in
  51. if (error == nil) {
  52. self.setMarkLocationInMap(searchResult: searchResult, location: location)
  53. print("locationdata",location)
  54. } else {
  55. print("error values",error as Any)
  56. }
  57. }
  58. }
  59.  
  60.  
  61. This error am getting some of locations
  62.  
  63. location address tile Reva University
  64. error values Optional(Error Domain=kCLErrorDomain Code=8 "(null)")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement