我想将GPS数据,如经度和纬度,添加到JPEG照片中。
该照片是通过点击卡片(NFC)进行捕获的。
在logcat中可以显示正确的值,但这些值无法写入jpg照片文件!
以下是我的代码: 它用于获取保存的jpg文件并调用下面的方法 该方法用于将EXIF GPS参数添加到jpg中 GPS参数,如经度和纬度,已在另一个活动中获取。
我使用Firefox中的EXIF Viewer查看结果。
IO异常的位置是否重要?
以下是可能导致失败的重要logcat日志: 07-26 11:48:30.386:D / NativeNfcTag(195):标签丢失,重新启动轮询循环
以下是调用方法的位置:
以下是我的代码: 它用于获取保存的jpg文件并调用下面的方法 该方法用于将EXIF GPS参数添加到jpg中 GPS参数,如经度和纬度,已在另一个活动中获取。
我使用Firefox中的EXIF Viewer查看结果。
IO异常的位置是否重要?
以下是可能导致失败的重要logcat日志: 07-26 11:48:30.386:D / NativeNfcTag(195):标签丢失,重新启动轮询循环
public static void writeFile (File photo, double latitude, double longitude) throws IOException{
ExifInterface exif = null;
try{
Log.v("latiDouble", ""+latitude);
Log.v("longiDouble", ""+longitude);
exif = new ExifInterface(photo.getCanonicalPath());
if (exif != null) {
double latitu = latitude;
double longitu = longitude;
double alat = Math.abs(latitu);
double along = Math.abs(longitu);
String stringLati = convertDoubleIntoDegree(alat);
String stringLongi = convertDoubleIntoDegree(along);
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, stringLati);
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, stringLongi);
Log.v("latiString", ""+ stringLati);
Log.v("longiString", ""+ stringLongi);
exif.saveAttributes();
String lati = exif.getAttribute (ExifInterface.TAG_GPS_LATITUDE);
String longi = exif.getAttribute (ExifInterface.TAG_GPS_LONGITUDE);
Log.v("latiResult", ""+ lati);
Log.v("longiResult", ""+ longi);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
以下是调用方法的位置:
Cursor locationCursor = dbHandler.fetchGpsLocationTypeByAttendInfoID(attendInfoId);
if (locationCursor.getCount()>0) {
double latitude = dbHandler.fetchDoubleItem(locationCursor,"LATITUDE");
double longitude = dbHandler.fetchDoubleItem(locationCursor,"LONGITUDE");
Log.v("latitude",""+latitude);
Log.v("latitude",""+longitude);
try {
GpsUtils.writeFile(photoFile, latitude, longitude);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
dbHandler.close();
cameraHandler.startPreview();