0

我需要获取摄像头拍摄的图像的经度和纬度。从摄像头获取经纬度Android

@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); 
} 
} 

此代码无效。我也找不到我要找的例子。我可能在尝试吗?谢谢。

回答

1

您的代码正在获取列索引,而不是实际值。这就是为什么你总是得到0和1.另外,坐标不是int。

正确的代码看起来是这样的:

// 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);