0

I need to pick up the longitude and latitude of an image taken by the camera.

@Override
        public void onClick(View v) {

            Intent i= new Intent("android.media.action.IMAGE_CAPTURE");
            startActivityForResult(i,TAKE_PHOTO);
        }

@Override

protected  void onActivityResult(int requestCode, int resultCode,Intent data){
 super.onActivityResult(requestCode,resultCode,data);

 switch(requestCode){
case TAKE_PHOTO:

    Bitmap imagen =(Bitmap) data.getExtras().get("data");
    Uri seleccion = (Uri) data.getExtras().get("uri");
    TextView jjj = (TextView) findViewById(R.id.comentarios);
    String [] fotoProyeccion ={MediaStore.Images.ImageColumns.LATITUDE,MediaStore.Images.ImageColumns.LONGITUDE};

     fotoDatos =Media.query(getBaseContext().getContentResolver(), seleccion, fotoProyeccion);

    int latt = fotoDatos.getColumnIndex (MediaStore.Images.ImageColumns.LATITUDE);
    int longi= fotoDatos.getColumnIndex(MediaStore.Images.ImageColumns.LONGITUDE);
    String resultado = String.valueOf(latt)+"---"+String.valueOf(longi);

    jjj.setText(resultado);
}
}

This code does not work. Nor do I find examples of what I'm looking for. Is it possible I am trying?. Thank you.

user1477173
  • 1
  • 1
  • 2

1 Answers1

1

Your code is getting the column indexes, not the actual values retured. That's why you always get 0 and 1. Also, coordinates are not int.

The correct code looks something like this:

// Query MediaStore
fotoDatos =Media.query(getBaseContext().getContentResolver(), seleccion, fotoProyeccion);

// Get the columns
int latcol = fotoDatos.getColumnIndex (MediaStore.Images.ImageColumns.LATITUDE);
int loncol = fotoDatos.getColumnIndex(MediaStore.Images.ImageColumns.LONGITUDE);

// Fetch first row
fotoDatos.moveToFirst();

// Get the actual values returned
double latval = fotoDatos.getDouble(latcol);
double lonval = fotoDatos.getDouble(loncol);

String resultado = String.valueOf(latval)+"---"+String.valueOf(lonval);
Alexandru Badiu
  • 350
  • 2
  • 7