title: Detecting touches on mkoverlay
body: <p>I'm drawing overlays based on directions. I draw from route a to route b and then route b to route c.</p>
  
  <p>I would like to detect if the overlay is tapped anywhere on mkoverlay.</p>
  
  <p>I used this example <a href="https://stackoverflow.com/questions/20858108/detecting-touches-on-mkoverlay-in-ios7-mkoverlayrenderer">Detecting touches on MKOverlay in iOS7 (MKOverlayRenderer)</a></p>
  
  <p>and converted it to swift.</p>
  
  <pre><code>override func touchesEnded(_ touches: Set&lt;UITouch&gt;, with event: UIEvent?) {
  
      if let touch = touches.first {
          if touch.tapCount == 1 {
              let touchLocation = touch.location(in: self)
              let locationCoordinate = self.convert(touchLocation, toCoordinateFrom: self)
  
              let mapPoint: MKMapPoint = MKMapPointForCoordinate(locationCoordinate)
              let mapPointAsCGP = CGPoint(x: CGFloat(mapPoint.x), y: CGFloat(mapPoint.y))
              for overlay: MKOverlay in self.overlays {
                  if (overlay is MKPolygon) {
                      let polygon: MKPolygon? = (overlay as? MKPolygon)
                      let mpr: CGMutablePath = CGMutablePath()
                      let polygonPoints = polygon?.points
                      let polygonPointCount = Int((polygon?.pointCount)!)
                      for p in 0..&lt;polygonPointCount {
                          let mp: MKMapPoint = polygonPoints.unsafelyUnwrapped()[polygonPointCount]
                          if p == 0 {
                              mpr.move(to: CGPoint(x: CGFloat(mp.x), y: CGFloat(mp.y)), transform: .identity)
                          }
                          else {
                              mpr.addLine(to: CGPoint(x: CGFloat(mp.x), y: CGFloat(mp.y)), transform: .identity)
                          }
                      }
  
                      if mpr.contains(mapPointAsCGP, using: .winding, transform: .identity) {
                          print("test")
                      }
                  }
              }
  
          }
      }
  
      super.touchesEnded(touches, with: event)
  }
  </code></pre>
  
  <p>I'm not sure why they have the if statement there </p>
  
  <pre><code>if (overlay is MKPolygon)  
  </code></pre>
  
  <p>because this would never be called since its an array of mkoverlay.</p>