Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Bitmap of MapView from Android Google Maps API V2

I'm updating my app to the new Android Maps API V2 and ran into a problem when trying to get a bitmap image of the currently shown map. In API V1 I did this like so:

Bitmap mBitmap;
MapViwe mMapView;
// ...
mBitmap = Bitmap.createBitmap(MAP_WIDTH, MAP_HEIGHT, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(mBitmap);
mMapView.draw(canvas);

Whilest in API V1, this got me a bitmap of the map, in API V2, all I get is a black rectangle.

Also with API V2 I'm using the MapView, not the MapFragment so this isn't the problem.

like image 502
Ridcully Avatar asked Jan 18 '13 10:01

Ridcully


1 Answers

GoogleMap.snapshot() method does the job.

like image 111
Viachaslau Tysianchuk Avatar answered Sep 20 '22 09:09

Viachaslau Tysianchuk