Document Maps SDK for iOS Guides Controls and Gestures Map Snapshot

Map Snapshot

The iOS Map SDK supports capturing a screenshot of a specified rectangular area (CGRect) on the screen. The captured content includes the map, map overlays, and callout bubbles.

Note: The screenshot feature depends on the map being displayed. Only content that is currently visible on the map can be captured.

Capture a Screenshot

Use the takeSnapshotInRect method in MAMapView to capture a screenshot. This method returns a UIImage object.

__block UIImage *screenshotImage = nil;
__block NSInteger resState = 0;
[self.mapView takeSnapshotInRect:inRect withCompletionBlock:^(UIImage *resultImage, NSInteger state) {
        screenshotImage = resultImage;
        resState = state; // state indicates whether the map is fully loaded: 0 = incomplete, 1 = complete
}];

Completion Block Parameters

Name

Required

Default

Meaning

Rule Description

resultImage

Yes

-

The captured screenshot image

Returns a UIImage object

state

Yes

-

Map loading state

0: The map is not fully loaded; 1: The map is fully loaded

Important

When the state parameter is 0, the screenshot may be incomplete, as shown in the following example:

Example of an incomplete map screenshot when the snapshot method is called before the map finishes rendering