Created
June 24, 2014 16:00
-
-
Save natesymer/2e0471b41bb7666efa7d to your computer and use it in GitHub Desktop.
Render maps in iOS 7 +
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <MapKit/MapKit.h> | |
typedef void (^MapViewRendererCallback)(UIImage *image); | |
@interface MapViewRenderer : NSObject | |
+ (void)renderMapRect:(MKMapRect *)mapRect withSize:(CGSize)size completion:(MapViewRendererCallback)block; | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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