获得图像照相机Android的纬度和经度 [英] get latitude and longitude from image camera Android

查看:392
本文介绍了获得图像照相机Android的纬度和经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要拿起相机拍摄的图像的经度和纬度。

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

这code不起作用。我也没有找到我要找的例子。是否有可能我想?谢谢你。

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

推荐答案

您code越来越列索引,而不是实际值retured。这就是为什么你总是得到0和1。此外,坐标不是int。

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.

正确的code看起来是这样的:

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

这篇关于获得图像照相机Android的纬度和经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆