The snapshot functionality of the Mapbox Maps SDK for Android generates a static map image to use in your Android project. Take a snapshot of any Mapbox map and add the image into:

  • another screen in your app
  • a home screen
  • a home screen widget
  • a notification
  • a list/RecyclerView
  • wherever else a Bitmap can be placed

A Mapbox map doesn't need to be displayed to use the snapshot functionality. MapSnapshotter can be invoked anywhere in the app.

Unless you have the map tiles already cached, the device will need an internet connection to download the style and tiles necessary to render the map, and thus, the snapshot.

Snapshot generation can happen on the device's background thread and won't compromise the user experience.

This snapshot feature is different than the Mapbox Static API. The MapboxStaticMap class helps you build a URL to request a static map image which looks like an embedded map without interactivity or controls.

Taking a map snapshot

The MapSnapshotter constructor requires a MapSnapshotter.Options object.

MapSnapshotter.Options snapShotOptions = new MapSnapshotter.Options(500, 500);
MapSnapshotter mapSnapshotter = new MapSnapshotter(this, snapShotOptions);

Here are the various settings that are available within the MapSnapshotter.Options class. You would use them in the same way that withRegion() and withStyle() are used in the code snippet above.

withCameraPositionThe camera position to use for the snapshot image. This position is overriden if withRegion is also used.
withLogoA boolean flag to determine whether the Mapbox logo is included in the snapshot image.
withPixelRatioThe pixel ratio to use. The default is 1.
withRegionThe region to show in the snapshot image. This is applied after the camera position.
withStyleThe map style to use in the snapshot image.
withStyleJsonThe map style JSON to use instead of a map style URL.

Start the snapshot process with start() once you've created your MapSnapshotter object. When MapSnapshot is ready, use snapshot.getBitmap() to retrieve the Bitmap image.

mapSnapshotter.start(new MapSnapshotter.SnapshotReadyCallback() {
public void onSnapshotReady(MapSnapshot snapshot) {
// Display, share, or use bitmap image however you'd like
Bitmap bitmapImage = snapshot.getBitmap();

Once you have the Bitmap image, you're free to use it however you'd like.

The Mapbox Android demo app has two examples that show how the snapshot Bitmap images can be used: