Android中的Google地图SnapShot无法正常工作

时间:2013-10-16 19:59:05

标签: android google-maps-android-api-2

GooglePlayServices的最新版本(12)包含用于截屏地图的文档(https://developers.google.com/maps/documentation/android/releases#august_2013)。这是我尝试的代码,我仍然得到一个黑屏:

public void captureMapScreen() {
    SnapshotReadyCallback callback = new SnapshotReadyCallback() {
        Bitmap bitmap;

        @Override
        public void onSnapshotReady(Bitmap snapshot) {
            bitmap = snapshot;
            try {
                FileOutputStream out = new FileOutputStream("/mnt/sdcard/" + "MyMapScreen" +
                                                            System.currentTimeMillis() + ".png");

                // above "/mnt ..... png" => is a storage path (where image will be stored) + name of image you can
                // customize as per your Requirement

                bitmap.compress(Bitmap.CompressFormat.PNG, 90, out);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    GoogleMap googleMap = getMap();
    googleMap.snapshot(callback);
}

enter image description here

0 个答案:

没有答案