jpeg写真に緯度経度などのGPSデータを追加したいです。写真はカード (NFC) をタブ操作することでキャプチャされます。logcat では正しい値を表示できますが、これらの値を jpg 写真ファイルに書き込むことはできません。
以下は私のコードです: 保存された jpg ファイルを取得し、以下のメソッドを呼び出すために使用されます メソッドは EXIF GPS パラメーターを jpg に追加するために使用されます 経度や緯度などの GPS パラメーターは、別のアクティビティで既に取得されています。
Firefox の EXIF Viewer を使用して結果を確認します。
IO 例外の位置は重要ですか?
以下は、失敗をレンダリングする可能性のある重要なログ cat ログです: 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();