Make a UIImage from a MKMapView or Other View


The improved function for retina display:


- (UIImage*) renderToImage
{
    if(UIGraphicsBeginImageContextWithOptions != NULL)
    {
        UIGraphicsBeginImageContextWithOptions(mapView.frame.size, NO, 0.0);
    } else {
        UIGraphicsBeginImageContext(mapView.frame.size);
    }
    [mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext(); 
    return image;
}