0

I have asked a question about taking a photo and returning that image to the point on the map where the users has tapped. Previously the camera intent would crash got it now to work without crashing the app but have the problem now of placing the image back into the map. Here is my updated code:

  @Override
  public void onMapLongClick(LatLng point) {
  Intent getCameraImage = new Intent(MediaStore.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, LatLng point) { 
    if(resultCode == RESULT_OK) {
        // This code here i think is wrong? 
        googleMap.addMarker(new MarkerOptions().position(point)
                .icon(BitmapDescriptorFactory.fromFile("photo")));
    }
}

when i take the photo and return to maps, then this is what i get from the log:

11-23 09:32:31.837: D/skia(12895): GFXPNG PNG bitmap created width:256 height:256 bitmap id is 486 

So in my mind it seems to be working, but not placing the image in the maps. Could anyone please help?

wemapps
  • 111
  • 8

1 Answers1

0

I do not think that the message you see in the log relates to the photo image - size 256x256 px is too small for camera, unless you specified it somehow when taking picture. It is unlikely.

The problem in your code is with BitmapDescriptorFactory.fromFile("photo"), you should use something like BitmapDescriptorFactory.fromPath(photo.getAbsolutePath()).

Mixaz
  • 3,989
  • 27
  • 54
  • Hi Thanks, I just tried that but still doesn't want to place the image onto the map. – wemapps Nov 23 '14 at 11:27
  • Try to place a marker without image first - does it work? If it does, then there's something with the image indeed. One of the reasons may be that the image too large. Print to log photo.getAbsolutePath() and check if the image is there, you can pull it from device with Android Device Monitor (in Android Studio menu Tools / Android). Also you should add logcat output to this issue, I'm almost sure there's some errors there. Someone already reported issues when GM marker is created from camera images http://stackoverflow.com/questions/16887017/google-map-custom-marker-out-of-memory-error-api-v2 – Mixaz Nov 23 '14 at 11:44
  • okay have tried that, removed the camera intent and just added mrker and that seems to work fine. I think the problem is when returning from the camera intent it doesn't place that image on the map. i'll try a different way now and let you know. – wemapps Nov 23 '14 at 12:10