Vote count:
0
I need to create a map, add an overlay to it and save it as image. I don't have any problem to do this BUT the thing is I need to do it without showing the map on screen. In fact, it must be done in a class that inherits from NSObject to be called from AppDelegate
I'm creating a map like this:
//Create map
self.mapView = MKMapView(frame: CGRectMake(0.0, 0.0, 260.0, 260.0))
self.mapView.delegate = self
And after doing overlay stuff (creating a route) I'm trying to get the image like this:
dispatch_async(dispatch_get_main_queue())
{
self.mapView.addOverlay(route!)
self.mapView.setVisibleMapRect(boundingRegion!, animated: false)
UIGraphicsBeginImageContext(self.mapView.bounds.size);
self.mapView.layer.renderInContext(UIGraphicsGetCurrentContext())
var mapImage = UIGraphicsGetImageFromCurrentImageContext()
if mapImage != nil
{
var data = UIImageJPEGRepresentation(mapImage,0.8)
//Continue saving data to documents folder
But I always get an empty image with the "Legal" text. I suppose the problem is that the map is never really rendered on a view and therefore the current context is empty. Is even possible to create a map like this and create the resulting image? Is there any way to specify a valid "context" to do this job?
Thx
asked 1 min ago
Create MKMapView without adding to view
Aucun commentaire:
Enregistrer un commentaire