title: Scaling MKMapView Annotations relative to the zoom level
body: <p><strong>The Problem</strong>
  I'm trying to create a visual radius circle around a annonation, that remains at a fixed size in real terms. Eg. So If i set the radius to 100m, as you zoom out of the Map view the radius circle gets progressively smaller.</p>
  
  <p>I've been able to achieve the scaling, however the radius rect/circle seems to "Jitter" away from the Pin Placemark as the user manipulates the view.</p>
  
  <p>I'm lead to believe this is much easier to achieve on the forthcoming iPhone OS 4, however my application needs to support 3.0.</p>
  
  <p><strong>The Manifestation</strong> 
  Here is a <a href="http://www.youtube.com/watch?v=0zQlgDoPXik" rel="noreferrer">video</a> of the behaviour.</p>
  
  <p><strong>The Implementation</strong>
  The annotations are added to the Mapview in the usual fashion, and i've used the delegate method on my UIViewController Subclass (<strong>MapViewController</strong>) to see when the region changes.</p>
  
  <pre><code>-(void)mapView:(MKMapView *)pMapView regionDidChangeAnimated:(BOOL)animated{
  
  //Get the map view
  MKCoordinateRegion region;
  CGRect rect;
  
  //Scale the annotations
  for( id&lt;MKAnnotation&gt; annotation in [[self mapView] annotations] ){
  
      if( [annotation isKindOfClass: [Location class]] &amp;&amp; [annotation conformsToProtocol:@protocol(MKAnnotation)] ){
          //Approximately 200 m radius
          region.span.latitudeDelta = 0.002f;
          region.span.longitudeDelta = 0.002f;
  
          region.center = [annotation coordinate];
  
          rect = [[self mapView] convertRegion:region toRectToView: self.mapView];
  
          if( [[[self mapView] viewForAnnotation: annotation] respondsToSelector:@selector(setRadiusFrame:)] ){
  
              [[[self mapView] viewForAnnotation: annotation] setRadiusFrame:rect];
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>The Annotation object (<strong>LocationAnnotationView</strong>)is a subclass of the MKAnnotationView and it's setRadiusFrame looks like this</p>
  
  <pre><code>-(void) setRadiusFrame:(CGRect) rect{
  
  CGPoint centerPoint;
  
  //Invert
  centerPoint.x = (rect.size.width/2) * -1;
  centerPoint.y = 0 + 55 + ((rect.size.height/2) * -1);
  
  rect.origin = centerPoint;
  
  [self.radiusView setFrame:rect];
  }
  </code></pre>
  
  <p>And finally the radiusView object is a subclass of a UIView, that overrides the drawRect method to draw the translucent circles. setFrame is also over ridden in this UIView subclass, but it only serves to call [UIView setNeedsDisplay] in addition to [UIView setFrame:] to ensure that the view is redrawn after the frame has been updated.</p>
  
  <p>The radiusView object's (<strong>CircleView</strong>) drawRect method looks like this</p>
  
  <pre><code>-(void) drawRect:(CGRect)rect{
  
  //NSLog(@"[CircleView drawRect]");
  
  [self setBackgroundColor:[UIColor clearColor]];
  //Declarations
  CGContextRef context;
  CGMutablePathRef path;
  
  //Assignments
  context = UIGraphicsGetCurrentContext();
  
  path = CGPathCreateMutable();
  
  //Alter the rect so the circle isn't cliped
  
  //Calculate the biggest size circle
  if( rect.size.height &gt; rect.size.width ){
      rect.size.height = rect.size.width;
  }
  else if( rect.size.height &lt; rect.size.width ){
      rect.size.width = rect.size.height;
  }
  
  rect.size.height -= 4;
  rect.size.width  -= 4;
  rect.origin.x += 2;
  rect.origin.y += 2;
  
  //Create paths
  CGPathAddEllipseInRect(path, NULL, rect );
  
  //Create colors
  [[self areaColor] setFill];
  
  CGContextAddPath( context, path);
  CGContextFillPath( context );
  
  [[self borderColor] setStroke];
  
  CGContextSetLineWidth( context, 2.0f );
  CGContextSetLineCap(context, kCGLineCapSquare);
  CGContextAddPath(context, path );
  CGContextStrokePath( context );
  CGPathRelease( path );
  
  //CGContextRestoreGState( context );
  
  }
  </code></pre>
  
  <p>Thanks for bearing with me, any help is appreciated.
  Jonathan</p>