사용자가 사진 갤러리에서 이미지를 선택하고 그 이미지가 EXIF 파일을 통해 현재 GPS 좌표를 가져 오는 지오 태깅 앱을 작성하려고합니다.안드로이드에서 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;
}
감사 :
여기 내 코드입니다!
편집 : 현재 파일 경로와 이름을 ExifInterface로 하드 코딩하려고 했으므로 filename
대신 "/sdcard/dcim/100MEDIA/IMAG0020.jpg"
이 표시됩니다. 그게 내 문제와 관련이 있을까요?
에 사용 된
picturePath
를 얻기 위해 코드를을 사용했다. 파일 경로를 하드 코딩하는 것이 문제였습니다. 나는 코드 을 사용했다. int columnIndex = cursor.getColumnIndex (filePathColumn [0]); String picturePath = cursor.getString (columnIndex); ' '및 'picturePath'를 사용했습니다. – user2340642