1

I am new to Android App development. And I want to implement the snapshot in the google map triggered by the info window on the map, then I need to return the image and crop it. Here is my code, but it doesn't work every time I touch the info window.

Here is the code of snapshot. When I debug it, I found that it jumped over the snapshot method, so I think that maybe my usage of snakshotReadyCallback is wrong.

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);
        }
    });
}

And here is the code of crop.

     //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);
        }
    }
Qianyuan
  • 11
  • 2

1 Answers1

0

Welcome on stackoverflow.

By implementing PlaceAutocompleteFragment and PlaceAutocompleteActivity , you can able to get google place.

See my question and answer which helps you.

Community
  • 1
  • 1
pRaNaY
  • 24,642
  • 24
  • 96
  • 146
  • Thanks, but because I do not using autocomplete fragment, I don't think implement that would be work for me, and I use PlaceAutocompleteActivity, but it cannot be implemented – Qianyuan Jul 08 '16 at 15:27