title: Why does the route not draw on the map with the following code?
body: <p>Could anyone help - the following code works in all regards except the route polyline is not drawn on the map - could you tell me what i am missing?</p>
  
  <p>I have been going around this particular tree for a VERY long time - LOL</p>
  
  <pre><code>import UIKit
  import MapKit
  
  protocol HandleMapSearch: class {
  func dropPinZoomIn(_ placemark:MKPlacemark)
  }
  
  class ViewController: UIViewController {
  
  var selectedPin: MKPlacemark?
  var resultSearchController: UISearchController!
  
  let locationManager = CLLocationManager()
  
  @IBOutlet weak var mapView: MKMapView!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      // Setup Location Manager Variables
  
      locationManager.delegate = self
      locationManager.desiredAccuracy = kCLLocationAccuracyBest
      locationManager.requestWhenInUseAuthorization()
      locationManager.requestLocation()
  
      //Setup Search Bar and Table
  
      let locationSearchTable = storyboard!.instantiateViewController(withIdentifier: "LocationSearchTable") as! LocationSearchTable
      resultSearchController = UISearchController(searchResultsController: locationSearchTable)
      resultSearchController.searchResultsUpdater = locationSearchTable
      let searchBar = resultSearchController!.searchBar
      searchBar.sizeToFit()
      searchBar.placeholder = "Do You Know Where You're Going To LA LA LA?"
      navigationItem.titleView = resultSearchController?.searchBar
      resultSearchController.hidesNavigationBarDuringPresentation = false
      resultSearchController.dimsBackgroundDuringPresentation = true
      definesPresentationContext = true
      locationSearchTable.mapView = mapView
      locationSearchTable.handleMapSearchDelegate = self
  }
  }
  
  extension ViewController : CLLocationManagerDelegate {
  
  // Find PolicyHolders current Location
  
  func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
      guard let location = locations.first else { return }
      let distancespan: CLLocationDegrees = 2000
      let PolicyHolderLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location.coordinate.latitude, location.coordinate.longitude)
  
      mapView.setRegion(MKCoordinateRegionMakeWithDistance(PolicyHolderLocation, distancespan, distancespan), animated:  true)
  
      // Drop pin at Policyholders current Location
  
      let PolicyHolderPin = Annotation(title: "Title", subtitle: "subtitle", coordinate: PolicyHolderLocation)
      mapView.addAnnotation( PolicyHolderPin )
      print (PolicyHolderLocation)
  }
  
  func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
      print("error:: \(error)")
  }
  }
  
  // Show queried location on map
  
  extension ViewController: HandleMapSearch {
  
  func dropPinZoomIn(_ placemark: MKPlacemark){
      // cache the pin
      selectedPin = placemark
      // clear existing pins
      //mapView.removeAnnotations(mapView.annotations)
      let annotation = MKPointAnnotation()
      annotation.coordinate = placemark.coordinate
      annotation.title = placemark.name
  
      if let city = placemark.locality,
          let state = placemark.administrativeArea {
          annotation.subtitle = "\(city) \(state)"
      }
  
      mapView.addAnnotation(annotation)
      let span = MKCoordinateSpanMake(0.05, 0.05)
      let region = MKCoordinateRegionMake(placemark.coordinate, span)
      mapView.setRegion(region, animated: true)
  }
  
  }
  
  // Drop Pin amd show route into queried location
  
  extension ViewController : MKMapViewDelegate {
  
  private func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) {
  
      //Drop Pin
      mapView.delegate = self
  
      // Convert source and destination routes to latitude and longitude
      let location = locationManager.location
      let sourceLocation:CLLocationCoordinate2D = CLLocationCoordinate2DMake(location!.coordinate.latitude, location!.coordinate.longitude)
  
      // Make them placemarks (probably a duplicate of above but I dont know how to call the existing policy holder placemark from the two functions)
      let sourcePlacemark = MKPlacemark(coordinate: sourceLocation, addressDictionary: nil)
  
      // Make them mapitems
      let sourceMapItem = MKMapItem(placemark: sourcePlacemark)
      let destinationMapItem = MKMapItem(placemark: selectedPin!)
  
      // set up and calculate the route
      let directionRequest = MKDirectionsRequest()
      directionRequest.source = sourceMapItem
      directionRequest.destination = destinationMapItem
      directionRequest.transportType = .automobile
  
      // Calculate the direction
      let directions = MKDirections(request: directionRequest)
  
      // Draw the directions (not working!!!)
      directions.calculate {
          (response, error) -&gt; Void in
  
          guard let response = response else {
              if let error = error {
                  print("Error: \(error)")
              }
  
              return
          }
  
          let route = response.routes[0]
          self.mapView.add((route.polyline), level: MKOverlayLevel.aboveRoads)
  
          let rect = route.polyline.boundingMapRect
          self.mapView.setRegion(MKCoordinateRegionForMapRect(rect), animated: true)
      }    }
  
  
  func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -&gt; MKOverlayRenderer {
      let renderer = MKPolylineRenderer(overlay: overlay)
      renderer.strokeColor = UIColor.red
      renderer.lineWidth = 4.0
  
      return renderer
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  }
  </code></pre>