-1

How can i declare a LatLng point in my map activity, so that when the users taps on a specific point on the map to place a marker. Now what i have done is to create a map so you can add your custom marker from camera intent ond place on the map. The problem isn't the fact that it works, however the fact that i have to declare a 'point' to the coordinates on a map then when the the image was taken it would place the thumbnail of that image at that point.

example: static final LatLng point = new LatLng(xx.xxxx, xx.xxxx);

and then in my onActivityResult from camera intent:

 MarkerOptions markerOptions = new MarkerOptions()
    .position(point)
    .icon(BitmapDescriptorFactory
    .fromBitmap(bitmap));
    googleMap.addMarker(markerOptions);

So what i want to do is to listen where the user has tapped and return that image to the point where tapped.

Could someone please help? If you need more info please let me know and will update my question.

Thanks

UPDATED CODE

 @Override
  public void onMapClick(LatLng point) {

          root = Environment.getExternalStorageDirectory().toString()
          + "/Your_Folder";
          imageFolderPath = root + "/saved_images";
          File imagesFolder = new File(imageFolderPath);
          imagesFolder.mkdirs();
          imageName = "test.png";
          File image = new File(imageFolderPath, imageName);

          fileUri = Uri.fromFile(image);

          Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

          takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);

          startActivityForResult(takePictureIntent,
                  CAMERA_IMAGE_REQUEST);

      }
    protected void onActivityResult(int requestCode, int resultCode, Intent data, LatLng point) {
          // TODO Auto-generated method stub
          super.onActivityResult(requestCode, resultCode, data);

          if (resultCode == RESULT_OK) {

              switch (requestCode) {
              case CAMERA_IMAGE_REQUEST:

                  Bitmap bitmap = null;
                  try {
                      GetImageThumbnail getImageThumbnail = new GetImageThumbnail();
                      bitmap = getImageThumbnail.getThumbnail(fileUri, this);
                  } catch (FileNotFoundException e1) {
                      e1.printStackTrace();
                  } catch (IOException e1) {
                      e1.printStackTrace();
                  }

                  MarkerOptions markerOptions = new MarkerOptions()
                  .position(point)
                  .icon(BitmapDescriptorFactory
                  .fromBitmap(bitmap));
                  googleMap.addMarker(markerOptions);

                  break;

              default:
                  Toast.makeText(this, "Something went wrong...",
                          Toast.LENGTH_SHORT).show();
                  break;
              }

          }
      }
      public void showFullImage(View view) {
            String path = (String) view.getTag();

            if (path != null) {

                Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                Uri imgUri = Uri.parse("file://" + path);
                intent.setDataAndType(imgUri, "image/*");
                startActivity(intent);

            }
Allrounder
  • 685
  • 2
  • 9
  • 20

1 Answers1

1

I think what you need is the OnMapClickListener

You have everything that you need in the documentation to get it working

Alexander
  • 165
  • 9
  • Thanks for the links, have read through it and tried to implement but still now luck, i might be wrong but i think because this is `MarkerOptions markerOptions = new MarkerOptions() .position(point) .icon(BitmapDescriptorFactory .fromBitmap(bitmap)); googleMap.addMarker(markerOptions);` is in my `onActivityResult` and not under `onMapClick` so i think i need to somehow point the poistion to the `onMapClick` event – Allrounder Nov 27 '14 at 09:56
  • As I understand, the problem now is how to chain the events. Your application is taking photo first, and after that offers a map to the user, to point where the photo is taken, right ? If that so, you need to keep the photo (declared out of onActivityResult) until the user points on map and in the "onMapClick" event place the marker on map. – Alexander Nov 27 '14 at 10:21
  • it makes sense what you saying, although what happens is the user points on the map, then camera activity starts, then thumbnail is created, then returns to map with thumbnail. Ill update my question with the code, if that migt help explain myself better? – Allrounder Nov 27 '14 at 10:30
  • Using the updated code it places the image somewhere in the south atlantic ocean under Ghana.... which is 1000's of mile away from it is supposed to be :-) – Allrounder Nov 27 '14 at 10:42
  • Your problem now is that you lose your LatLng point because you are starting another process and the previous is being terminated and then restarted and your point is always at the center of Google's world map. Read a little bit about ways how to save the coordinates and retrieve them in the onActivityResult. http://stackoverflow.com/questions/7179706/android-local-variable-gets-lost-when-using-camera-intent – Alexander Nov 27 '14 at 11:50
  • Thank you but doe you have some example for me as well, as i have had a look at that but can't figure out what to do exactly? – Allrounder Nov 27 '14 at 12:17
  • This is common question, you can easily find example. Try using the onSaveInstanceState() and onRestoreInstanceState() methods to save the coordinates. Here's an example http://stackoverflow.com/questions/151777/saving-activity-state-in-android And if you're still confused look at the Android Activity Lifecycle.... – Alexander Nov 28 '14 at 09:11
  • Thanks, I know that i have to use that, but not sure how to implement it into my code. Could you possibly help? – Allrounder Nov 28 '14 at 09:28
  • Make a variables for longitude and latidute. When Map is tapped onMapClick event is started and here you put the tapped longitude and latitude in the variables and start the camera intent. Your InstanceState methods should be written so when you take picture and get back to your activity your coordinates should be restored in the instance restore method. So in OnActivityResult you should be able to get your coordinates from the variables and put the map pointer on the exact place – Alexander Nov 28 '14 at 09:56