Search code examples
iosobjective-cgoogle-maps-sdk-ios

Google Map layer snapshot in iOS 17.2 is blank


I have developed an iOS app (way back with ObjectiveC) which creates an image of the current Google Map on the screen. I always have used this code, which ran fine:

UIGraphicsBeginImageContextWithOptions(self.map.frame.size, NO, 0.0);
[self.map.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;

Now I have the problem that since iOS 17.2 the image is empty (only the Google logo is shown, but no map information at all).

Does anybody know what the issue is?

Thx, Danny


Solution

  • I found the solution. I am now using:

    [self.map drawViewHierarchyInRect:self.map.bounds afterScreenUpdates:YES];

    Code:

    UIGraphicsBeginImageContext(self.map.bounds.size);
    [self.map drawViewHierarchyInRect:self.map.bounds afterScreenUpdates:YES];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;