我們將共享一個解決方案,其中包括在JPEG圖像文件中保存和檢索位置。使用ExifInterface 保存和檢索圖像元數據中的經度和緯度。有關ExifInterface的更多信息,請點擊此處 http://developer.android.com/reference/android/media/ExifInterface.html在JPEG圖像中保存和檢索位置
0
A
回答
2
public void saveLocation() {
ExifInterface exif = null;
try {
exif = new ExifInterface(imagePath);
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, latitude);
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, longitude);
exif.saveAttributes();
} catch (IOException e) {
e.printStackTrace();
}
}
public void retriveLocation() {
ExifInterface exif = null;
try {
exif = new ExifInterface(imagePath);
String[] latitudeValue = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE).split(",");
String[] longitudeValue = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE).split(",");
String[] tmp = new String[2];
tmp = latitudeValue[0].split("/");
setLatitude(String.valueOf(Float.valueOf(tmp[0])/Float.valueOf(tmp[1])));
tmp = longitudeValue[0].split("/");
setLongitude(String.valueOf(Float.valueOf(tmp[0])/Float.valueOf(tmp[1])));
} catch (IOException e) {
e.printStackTrace();
}
}
0
使用ExifInterface
你可以得到以下從媒體信息。
變量聲明。使用
String mediaDateTime,attrLATITUDE,attrLATITUDE_REF,attrLONGITUDE,attrLONGITUDE_REF,zip, city,state, country;;
Double Latitude, Longitude;
List<Address> addresses;
Geocoder geocoder;
用戶ExifInterface
follwing方式。
ExifInterface exifInterfaceMedia = new ExifInterface(<Your Image Path>);
// This will give you data and time
mediaDateTime = exifInterfaceMedia.getAttribute(ExifInterface.TAG_DATETIME);
attrLATITUDE = exifInterfaceMedia.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
attrLATITUDE_REF = exifInterfaceMedia.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
attrLONGITUDE = exifInterfaceMedia.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
attrLONGITUDE_REF = exifInterfaceMedia.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
if ((attrLATITUDE != null) && (attrLATITUDE_REF != null) && (attrLONGITUDE != null) && (attrLONGITUDE_REF != null)) {
valid = true;
if (attrLATITUDE_REF.equals("N")) {
Latitude = convertToDegree(attrLATITUDE);
} else {
Latitude = 0 - convertToDegree(attrLATITUDE);
}
if (attrLONGITUDE_REF.equals("E")) {
Longitude = convertToDegree(attrLONGITUDE);
} else {
Longitude = 0 - convertToDegree(attrLONGITUDE);
}
try {
addresses = geocoder.getFromLocation(Latitude, Longitude, 1);
} catch (IOException e) {
e.printStackTrace();
}
if (addresses != null && addresses.size() > 0) {
zip = addresses.get(0).getPostalCode();
city = addresses.get(0).getLocality();
state = addresses.get(0).getAdminArea();
country = addresses.get(0).getCountryName();
if (zip != null) {
title += zip + ",";
}
if (city != null) {
title += city + ",";
}
if (state != null) {
title += state + ",";
}
if (country != null) {
title += country;
}
} else {
title = "Unknown Location";
}
}
private Double convertToDegree(String stringDMS) {
Double result = null;
String[] DMS = stringDMS.split(",", 3);
String[] stringD = DMS[0].split("/", 2);
Double D0 = new Double(stringD[0]);
Double D1 = new Double(stringD[1]);
Double FloatD = D0/D1;
String[] stringM = DMS[1].split("/", 2);
Double M0 = new Double(stringM[0]);
Double M1 = new Double(stringM[1]);
Double FloatM = M0/M1;
String[] stringS = DMS[2].split("/", 2);
Double S0 = new Double(stringS[0]);
Double S1 = new Double(stringS[1]);
Double FloatS = S0/S1;
result = new Double(FloatD + (FloatM/60) + (FloatS/3600));
return result;
}
相關問題
- 1. 如何將(Jpeg)圖像保存到MySql並在以後檢索?
- 2. 如何檢索我保存在臨時位置的圖像
- 3. 將圖像從位圖保存到jpeg而不保存文件
- 4. 檢索JPEG圖像和GUI窗口
- 5. 保存和檢索圖像的問題
- 6. 如何在sdcard上保存jpeg的位圖圖像?
- 7. 保存所有圖像爲jpeg在php
- 8. 檢索圖像保存在數據庫
- 9. 如何將位圖圖像保存爲JPEG
- 10. 關於在android中保存和檢索圖像的說明
- 11. 如何在asp.net中保存和檢索圖像
- 12. 如何在swift中保存和檢索svg圖像。
- 13. 保存當前位置,並檢索
- 14. 保存和從孤立存儲中檢索圖像時出錯
- 15. 在C#中的位置保存位圖圖像
- 16. 無法將位圖保存爲JPEG
- 17. 保存和檢索iOS和SQLite中的圖像
- 18. 保存和檢索內存位置的值
- 19. 保存位爲JPEG文件
- 20. 如何保存圖像jpeg文件?
- 21. asp.net圖像jpeg沒有正確保存
- 22. 在Matlab中將位圖圖像保存爲位圖圖像
- 23. 保存/檢索圖像。 ASP.NET MVC
- 24. 保存並檢索圖像 - Ios
- 25. Android使用Base64保存和檢索JPEG文件
- 26. 位圖旋轉和保存圖像
- 27. 問題保存和檢索android中的圖像?
- 28. 檢索在db中保存的配置
- 29. 圖像的保存/加載位置
- 30. 將圖像保存到指定位置
感謝分享 – Moudiz