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