Skip to content

Instantly share code, notes, and snippets.

@natesymer
Created June 24, 2014 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natesymer/2e0471b41bb7666efa7d to your computer and use it in GitHub Desktop.
Save natesymer/2e0471b41bb7666efa7d to your computer and use it in GitHub Desktop.
Render maps in iOS 7 +
#import <MapKit/MapKit.h>
typedef void (^MapViewRendererCallback)(UIImage *image);
@interface MapViewRenderer : NSObject
+ (void)renderMapRect:(MKMapRect *)mapRect withSize:(CGSize)size completion:(MapViewRendererCallback)block;
@end
#import "MapViewRenderer.h"
@implementation MapViewRenderer
+ (void)renderMapRect:(MKMapRect *)mapRect withSize:(CGSize)size completion:(MapViewRendererCallback)block {
MKMapSnapshotOptions *options = [[MKMapSnapshotOptions alloc]init];
options.region = MKCoordinateRegionForMapRect(mapRect);
options.scale = [UIScreen mainScreen].scale;
options.size = size;
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc]initWithOptions:options];
[snapshotter startWithCompletionHandler:^(MKMapSnapshot *snapshot, NSError *error) {
block(snapshot.image);
}];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment