In my iOS app, I intend to get a snapshot of my Google Maps map with the following code:
UIGraphicsBeginImageContext(self.mapView.frame.size)
if let context = UIGraphicsGetCurrentContext() {
self.mapView.layer.render(in: context)
}
self.imageSnapshot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
However, the image returned is a black screen image with the Google Logo on the bottom left. What can I do to get the correct image snapshot of the map?
Assuming mapView is an instance of GMSMapView, the following should work
let image = UIGraphicsImageRenderer(size: mapView.bounds.size).image { _ in
mapView.drawHierarchy(in: mapView.bounds, afterScreenUpdates: true)
}
This is assuming the map has actually rendered before this code is called of course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With