如何在android中的谷歌地图中实现快照

时间:2016-07-08 15:00:08

标签: android google-maps android-studio crop snapshot

我是Android App开发的新手。我想在地图上的信息窗口触发的谷歌地图中实现快照,然后我需要返回图像并裁剪它。 这是我的代码,但每次触摸信息窗口时它都不起作用。

这是快照的代码。当我调试它时,我发现它跳过了快照方法,所以我想也许我对snakshotReadyCallback的使用是错误的。

public void takeSnapShot(){
    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            //final ImageView snapshotHolder = (ImageView) findViewById(R.id.picture);
            final GoogleMap.SnapshotReadyCallback callback = new GoogleMap.SnapshotReadyCallback() {
                @Override
                public void onSnapshotReady(Bitmap snapshot) {
                    //snapshotHolder.setImageBitmap(snapshot);
                    try {
                        FileOutputStream out = new FileOutputStream("test.png");
                        snapshot.compress(Bitmap.CompressFormat.PNG, 90, out);
                        Toast.makeText(MapsActivity.this, "Capture OK", Toast.LENGTH_LONG).show();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            mMap.snapshot(callback);
        }
    });
}

这是庄稼的代码。

     //crop the image
public void performCrop(){
    try{
        Intent cropIntent= new Intent("com.android.camera.action.CROP");
        cropIntent.setDataAndType(picUri,"map/*");
        cropIntent.putExtra("crop", "true");
        cropIntent.putExtra("aspectX", 2);
        cropIntent.putExtra("aspectY", 1);
        cropIntent.putExtra("outputX", 256);
        cropIntent.putExtra("outputY", 256);
        cropIntent.putExtra("return-data", true);
        startActivityForResult(cropIntent, CROP_PIC);
    }catch (ActivityNotFoundException anfe){
        Toast.makeText(this, "this device doesn't support crop", Toast.LENGTH_SHORT).show();
    }
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CROP_PIC) {
            Bundle extras = data.getExtras();
            Bitmap thePic = extras.getParcelable("data");
            ImageView picView = (ImageView) findViewById(R.id.picture);
            picView.setImageBitmap(thePic);
        }
    }

1 个答案:

答案 0 :(得分:0)

欢迎使用stackoverflow。

通过实施 PlaceAutocompleteFragment PlaceAutocompleteActivity ,您可以获得Google地址。

请参阅我的question and answer帮助您。