Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get map image from MKMapView

Tags:

iphone

I have place a mapview as hidden in my application. The map image need to be obtained from the mapview and send as email. How can i get the map image from the hidden mapview.

Thanks,

like image 855
Timmi Avatar asked Oct 12 '09 09:10

Timmi


1 Answers

For SDK:

UIGraphicsBeginImageContext(self.mapView.bounds.size);
[self.mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *mapImage = UIGraphicsGetImageFromCurrentImageContext();

For toolchain (using Private API)

CGRect rect = [self.mapView bounds];
// Change the snapshot rect if needed. 
CGImageRef image = [self.mapView createSnapshotWithRect:rect];
like image 82
Mike Chen Avatar answered Sep 30 '22 05:09

Mike Chen