【发布时间】:2012-07-23 14:21:00
【问题描述】:
我想将经度和纬度等 GPS 数据添加到 jpeg 照片中。 照片是通过标签卡(NFC)拍摄的 在 logcat 中可以显示正确的值,但这些值无法写入 jpg 照片文件!
以下是我的代码: 用于获取保存的jpg文件并调用下面的方法 该方法用于将EXIF GPS参数添加到jpg中 经纬度等 GPS 参数已在其他活动中获取。
我在 Firefox 中使用 EXIF 查看器来查看结果。
IO Exception 的位置重要吗?
以下是可能导致失败的重要日志猫日志: 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();
【问题讨论】:
-
我们可能需要有关您的代码功能的更多信息(单步执行并解释每一行的功能也可能会引导您找到解决方案)以及您已经针对该问题所做的任何研究.例如,如果你得到一个异常,那么异常是什么?基本上,如果您认为它可以帮助某人回答问题,那么添加它会很棒。
-
我所看到的是参数设置是有效的,并且能够从 logcat 中显示,但是当通过 Firefox 的 EXIF 查看器打开 iamges 时,我看不到任何写入的 GPS 数据图片。
标签: android gps location jpeg exif