Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Geolocation 如何在Android上将GPS坐标写入EXIF数据_Geolocation_Gps_Jpeg_Exif - Fatal编程技术网

Geolocation 如何在Android上将GPS坐标写入EXIF数据

Geolocation 如何在Android上将GPS坐标写入EXIF数据,geolocation,gps,jpeg,exif,Geolocation,Gps,Jpeg,Exif,我正在尝试编写一个地理标签应用程序,其中用户从照片库中选择一幅图像,然后该图像通过其EXIF文件获取当前GPS坐标 到目前为止,我能够打开图库,选择一幅图像,并找到我当前的GPS坐标,但我无法将这些坐标写入EXIF文件。无论何时选择图像,我都可以查看它,但没有数据写入EXIF文件 我已经查阅了几个如何编写EXIF的示例,我的代码看起来是正确的(至少对我来说)。有人能帮我弄清楚为什么我不写任何数据吗 这是我的密码: //place GPS cords into exif file

我正在尝试编写一个地理标签应用程序,其中用户从照片库中选择一幅图像,然后该图像通过其EXIF文件获取当前GPS坐标

到目前为止,我能够打开图库,选择一幅图像,并找到我当前的GPS坐标,但我无法将这些坐标写入EXIF文件。无论何时选择图像,我都可以查看它,但没有数据写入EXIF文件

我已经查阅了几个如何编写EXIF的示例,我的代码看起来是正确的(至少对我来说)。有人能帮我弄清楚为什么我不写任何数据吗

这是我的密码:

//place GPS cords into exif file
        try {
            ExifInterface exif = new ExifInterface("/sdcard/dcim/100MEDIA/IMAG0020.jpg");

            exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, DMSconv(lat));
            exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE,DMSconv(lon));
            if (lat > 0) 
              exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "N"); 
            else              
              exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, "S");
            if (lon > 0) 
              exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "E");    
             else             
               exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, "W");
            exif.saveAttributes();

        } catch (IOException e) {
            e.printStackTrace();
        }

 //convert from decimal degrees to DMS
String DMSconv(double coord) {  
      coord = (coord > 0) ? coord : (-1)*coord;  // -105.9876543 -> 105.9876543
      String sOut = Integer.toString((int)coord) + "/1,";   // 105/1,
      coord = (coord % 1) * 60;         // .987654321 * 60 = 59.259258
      sOut = sOut + Integer.toString((int)coord) + "/1,";   // 105/1,59/1,
      coord = (coord % 1) * 6000;             // .259258 * 6000 = 1555
      sOut = sOut + Integer.toString((int)coord) + "/1000";   // 105/1,59/1,15555/1000
      return sOut;
    }
谢谢你的帮助


编辑:此时我正试图将文件路径和名称硬编码到ExiFinInterface中,所以它会显示
“/sdcard/dcim/100MEDIA/imag020.jpg”
,而不是
文件名
。这和我的问题有什么关系吗?

解决了。硬编码文件路径是问题所在。我用了密码

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
获取
图片路径
,然后在

ExifInterface exif = new ExifInterface(picturePath);

解决了。硬编码文件路径是问题所在。我使用了代码
int columnIndex=cursor.getColumnIndex(filePathColumn[0]);String picturePath=cursor.getString(columnIndex)和使用的
图片路径