0

I have implemented a longclick listener in google maps. so when the user long click on the map it starts the camera intent and then you can take a picture. Now what i want to achieve is when that image is taken to get placed on the point on the map the users long clicked on.

googleMap.setOnMapLongClickListener(Test.this);
 googleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

 // adding marker

 googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
 googleMap.setMyLocationEnabled(true); // false to disable
 googleMap.getUiSettings().setZoomControlsEnabled(false); // true to enable
 googleMap.getUiSettings().setCompassEnabled(true);
 googleMap.getUiSettings().setMyLocationButtonEnabled(true); 

   }
  {
 }

  @Override
   public void onMapLongClick(LatLng point) {
   Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    startActivityForResult(intent,TAKE_PICTURE);
   googleMap.addMarker(new MarkerOptions().position(point)
            .icon(BitmapDescriptorFactory.fromResource(TAKE_PICTURE)));

   Toast.makeText(getApplicationContext(),
         "New marker added@" + point.toString(), Toast.LENGTH_LONG)
         .show();
   }
   }

So basically now the app crashes, the weird thing is that i can't seem to check the error message (logcat) cuase as soon as it comes up it dissapears again. (i have tried printscreen, but not fast enough :-) )

Could anyone please shed some light on this and what i can do to resolve this?

Thanks

wemapps
  • 111
  • 8
  • there's special button in Eclipse and Android Studio to stop auto-scrolling for logcat window. Also you can execute from command line "adb logcat -d >log.txt" to get the log in a file – Mixaz Nov 22 '14 at 18:38

1 Answers1

0

This looks wrong for me:

startActivityForResult(intent,TAKE_PICTURE);
googleMap.addMarker(new MarkerOptions().position(point)
        .icon(BitmapDescriptorFactory.fromResource(TAKE_PICTURE)));

The first statement uses TAKE_PICTURE as a request code for started Activity. This is probably right. The second statement uses TAKE_PICTURE as a resource identificator (to something in your 'res' folder). Most likely the second statement throws an exception because there's no resource for that identificator, or it is of a wrong type for BitmapDescriptorFactory.

When you call startActivityForResult then camera app starts, and it will take some time while user makes a shot (or cancels camera app by BACK button). You can't access captured photo immediately, you need to do that in onActivityResult handler, ie:

private File photo = null;
/**
 * This method is used to start the camera activity and save the image taken as the imagename passed 
 * 
 * @param imagename : this is the name of the image which will be saved 
 */
private void clickPicture(String imagename) {
    Intent getCameraImage = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // this is the same as ""android.media.action.IMAGE_CAPTURE"
    File cameraFolder;
    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
        cameraFolder = new File(android.os.Environment.getExternalStorageDirectory(),"myfolder/");
    else
        cameraFolder= context.getCacheDir();
    if(!cameraFolder.exists())
        cameraFolder.mkdirs();
    String imageFileName = imagename;
    photo = new File(cameraFolder, "myfolder/" + imageFileName);
    getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    Uri.fromFile(photo);
    startActivityForResult(getCameraImage, TAKE_PICTURE);

}    

protected void onActivityResult(int requestCode, int resultCode, Intent intent) { 
    if(resultCode == RESULT_OK) {
        // read captured image from File photo and place it to map
    }
}

Since the image will be large for a marker, you should resample it to something smaller. It is other question, google for it ))

The image file will be saved in external storage of the app (on SD card), if it is mounted. Otherwise it the file will be placed to application's cache dir in internal memmory.

Mixaz
  • 3,989
  • 27
  • 54
  • Great thank you! got it to work without crashing, but can't seem to place the image back into map. (not to worried about resizing yet, just want to get it to place image in map) I'll ask a new question with updated code. – wemapps Nov 23 '14 at 07:06
  • 1
    Hi i have asked another question here is the link [http://stackoverflow.com/questions/27086649/how-to-place-taken-photo-from-camera-intent-and-place-in-maps-where-users-has-ta] – wemapps Nov 23 '14 at 07:40