title: Showing annotations only inside the overlays
body: <p>In my map, I have to show annotations from a kml file via an URL. I also need to show only the annotations inside a polygon or circle area (or both of them if the user has both overlays drawn).</p>
  
  <p>I have seen the question <a href="https://stackoverflow.com/questions/4354130/how-to-determine-if-an-annotation-is-inside-of-mkpolygonview-ios/4354250#4354250">How to determine if an annotation is inside of MKPolygonView (iOS)</a>, but I have two perplexities:</p>
  
  <ol>
  <li>Regarding the annotation coordinates, should I use the coordinates of the annotations from the <code>addAnnotation</code> method?</li>
  <li>In the mentioned question a new overlay is created, but I have two different overlays created elsewhere. So my question is: what is the most suitable place to put this code (or something like that)?</li>
  </ol>
  
  <p><strong>EDIT</strong>: I've created some code:</p>
  
  <pre><code>-(IBAction)showKmlData:(id)sender
  {
  NSString *path = [[NSBundle mainBundle] pathForResource:@"KMLGenerator" ofType:@"kml"];
  
  kml = [[KMLParser parseKMLAtPath:path] retain];
  
  NSArray *annotationsImmut = [kml points];
  //[mapview addAnnotations:annotations]; not anymore
  NSMutableArray *annotations = [annotationsImmut mutableCopy];
  [self filterAnnotations:annotations];
  
  MKMapRect flyTo = MKMapRectNull;
  
  for (id &lt;MKAnnotation&gt; annotation in annotations) {
      MKMapPoint annotationPoint = MKMapPointForCoordinate(annotation.coordinate);
      MKMapRect pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0);
      if (MKMapRectIsNull(flyTo)) {
          flyTo = pointRect;
      } else {
          flyTo = MKMapRectUnion(flyTo, pointRect);
      }
  }
  
  mapview.visibleMapRect = flyTo;
  }
  
  
  -(void)filterAnnotations:(NSMutableArray *)annotationsToFilter {
  
  for (int i=0; i&lt;[annotationsToFilter count]; i++) {
  
      CLLocationCoordinate2D mapCoordinate = [[annotationsToFilter objectAtIndex:i] coordinate];
  
      MKMapPoint mapPoint = MKMapPointForCoordinate(mapCoordinate);
  
      MKPolygonView *polygonView = 
          (MKPolygonView *)[mapView viewForOverlay:polygonOverlay];
  
      MKCircleView *circleView = 
          (MKCircleView *)[mapView viewForOverlay:circleOverlay];
  
      CGPoint polygonViewPoint = [polygonView pointForMapPoint:mapPoint];
      CGPoint circleViewPoint = [circleView pointForMapPoint:mapPoint];
  
      BOOL mapCoordinateIsInPolygon = 
          CGPathContainsPoint(polygonView.path, NULL, polygonViewPoint, NO);
  
      BOOL mapCoordinateIsInCircle = 
          CGPathContainsPoint(circleView.path, NULL, circleViewPoint, NO);
  
          if( mapCoordinateIsInPolygon || mapCoordinateIsInCircle )
              [annotationsToFilter removeObjectAtIndex:i];
  }
  [mapView addAnnotations:annotationsToFilter];
  }
  </code></pre>
  
  <p><strong>EDIT Nr.2</strong> Here is my implementation of viewForOverlay delegate method.I see the overlays, circles and polygons I create.I see all the annotations.ALL of them, those inside and outside the overlays...</p>
  
  <pre><code>-(MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id)overlay 
  {
      MKCircleView* circleView = [[[MKCircleView alloc] initWithOverlay:overlay] autorelease];
  circleOverlay = circleView;
      circleView.fillColor = [UIColor blueColor];
      circleView.strokeColor = [UIColor blueColor];
      circleView.lineWidth = 5.0;
      circleView.alpha = 0.20;
  
      MKPolygonView *polygonView = [[[MKPolygonView alloc] initWithOverlay:overlay] autorelease];
  polygonOverlay = polygonView;
      polygonView.fillColor = [UIColor blueColor];
      polygonView.strokeColor = [UIColor blueColor];
      polygonView.lineWidth = 5.0;
      polygonView.alpha = 0.20;
  
  
  if ([overlay isKindOfClass:[MKCircle class]])
  {   
      return circleView;
  }
  
  else
      return polygonView;
  </code></pre>
  
  <p>}</p>