Good day everybody!
I’m developing application for iPhone. I have table view and list of locations that I need to display to user. For this purpose I used MKMapView in every table view cell. But when there are a lot of locations this solution becomes very slow. I want to improve UI performance and replace MKMapView with UIImageView. So I need to render map from MKMapView to UIImage in some NON-MAIN thread. I tried to do it like this:
UIGraphicsBeginImageContext(CGSizeMake(64, 64));
CGContextRef context = UIGraphicsGetCurrentContext();
[[mapView layer] renderInContext:context];
thumbnail_image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
But this code renders only yellow background of the map and pin above specified location. There is no map data such streets, houses, etc. What did I do wrong? Thank You for advice.
The reason that you aren’t getting any map data is that you aren’t waiting for the map data to load. Wait until the map view’s
mapViewDidFinishLoadingMap:delegate method is called, then take the picture. You might have to take the picture after a small delay, one or two seconds, after the delegate method is called, as I have found that sometimes the delegate method is called a bit early as I mention in this question.Note: You’ll want to make the dimensions of your map view square so that when you render it in a square image it won’t be stretched awkwardly.