我想将经度和纬度等 GPS 数据添加到 jpeg 照片中。通过标签卡(NFC)捕获照片在logcat中可以显示正确的值,但这些值不能写入jpg照片文件!
下面是我的代码: 用于获取保存的jpg文件并调用下面的方法 该方法用于将EXIF GPS参数添加到jpg中 经度和纬度等GPS参数已经在另一个活动中获取。
我在 Firefox 中使用 EXIF 查看器来查看结果。
IO Exception 的位置重要吗?
以下是可能导致失败的重要日志 cat log: 07-26 11:48:30.386: D/NativeNfcTag(195): Tag lost, restarting polling loop
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();