I have a situation whereby I need a way of loading an MKMapView with several overlays. This map view shouldn’t be shown onscreen, the only reason I require it to load is in order to create an image from the map for use elsewhere.
I have had a look around online but I haven’t had any luck with finding a solution to the problem. Please can someone help me out?
Here is what I’ve tried so far (with no success)
// Load the map view
Logs_Map_ViewController *mapViewController = [[Map_ViewController alloc] initWithNibName:@"Map_ViewController" bundle:nil];
mapViewController.GPSCoordinatesToPlot = [someDictionary objectForKey:kGPSCoords];
// Take a picture of the map
UIImage *mapImage = [mapViewController convertMapToImage];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(mapImage)];
NSString *base64String = [imageData base64EncodedString];
NOTE: It’s really important that the app waits for the map to fully load (so that the image is created properly).
You should be able to implement
mapViewDidFinishLoadingMapin theMKMapViewDelegateprotocol and store your image there, I would think. That should solve the problem of needing to wait until the map is loaded to store the image.If you’re seeing other issues as well, please provide more detail on those, as your question is not clear on the specific issue(s) that you’re asking about.