title: Rotate annotation image on MKMapView
body: <p>I am trying to rotate an image that is added to MKMapView as an annotation.</p>
  
  <p>This is the code:</p>
  
  <pre><code>-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:   (id&lt;MKAnnotation&gt;)annotation
  {
    if (! [annotation isKindOfClass:[IGAMapAnnotation class]])
    {
      //return default view if annotation is NOT of type IGAMapAnnotation...
      return nil;
    }
  
  
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"IGAMapAnnotation"];
  
    if (annotationView == nil)
    {
      annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"IGAMapAnnotation"];
  
      annotationView.enabled = YES;
      annotationView.canShowCallout = YES;
      annotationView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    }
    else
    {
      annotationView.annotation = annotation;
    }
  
    IGAMapAnnotation *myLocation = (IGAMapAnnotation *) annotation;
  
    // THIS IS IT!
    if ([myLocation.type isEqual: @"PLANE"]) {
      UIImage *planeImage = [UIImage imageNamed:@"planetracked.png"];
  
      UIImageView *planeImageView = [[UIImageView alloc]initWithImage:planeImage];
      planeImageView.transform = CGAffineTransformMakeRotation(M_PI_2);
  
      annotationView.image = planeImageView;
    }
  
    return annotationView;
  }
  </code></pre>
  
  <p>It obviously gives me an error as annotationView.image should assign an image and not UIImageView. I have tried various methods rotating just an image, for example this:</p>
  
  <pre><code>- (UIImage *)rotateImage:(UIImage *)image onDegrees:(NSString *)heading {
  
    double angle = [heading doubleValue];
  
    CGSize s = {image.size.width, image.size.height};
    UIGraphicsBeginImageContext(s);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextTranslateCTM(ctx, 0,image.size.height);
    CGContextScaleCTM(ctx, 1.0, -1.0);
  
    CGContextRotateCTM(ctx, 2*M_PI*angle/360);
    CGContextDrawImage(ctx,CGRectMake(0,0,image.size.width, image.size.height),image.CGImage);
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
  }
  </code></pre>
  
  <p>They do not work either -- no image appears on the map.</p>
  
  <p>Anyone knows how to rotate an annotation image on MKMapView?</p>
  
  <p>Million thanks!</p>