Is it possible to make a png or data-url of the current view on the map?
Asked
Active
Viewed 633 times
2 Answers
4
You can simply save the current map as a .png
, by taking a screenshot (MapboxMap#snapshot
) after the map has loaded.
Ensure you've got the appropriate build.gradle
dependency:
implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:5.3.0-SNAPSHOT@aar'){
transitive = true
}
Code for capturing the map:
private void captureScreen() {
mMapBoxMap.snapshot(new MapboxMap.SnapshotReadyCallback() {
@Override
public void onSnapshotReady(Bitmap snapshot) {
ImageView snapshotView = (ImageView) findViewById(R.id.);
snapshotView.setImageBitmap(snapshot);
}
});
}
Hope this helps you.

Tom Larcher
- 661
- 9
- 24

sabith.ak
- 255
- 4
- 12
-
This won't work as the map referred in the OP is a SurfaceView (when creating images as shown in this answer, you will get a black image without a map) – Tobrun Dec 07 '17 at 06:53
1
There are 2 ways of getting a map bitmap:
- from an existing map with
MapboxMap#snapshot(SnapshotReadyCallback)
- without an existing map using the
MapSnapshotter.java
class and the related options class.

Tobrun
- 18,291
- 10
- 66
- 81