get latitude and longitude from image camera Android

不羁的心 提交于 2019-12-12 03:45:19

问题


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.


回答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);


来源:https://stackoverflow.com/questions/11187717/get-latitude-and-longitude-from-image-camera-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!