//Gps纬度
double lat = GpsTracking.bestLocation.getLatitude();
//Gps经度
double lon = GpsTracking.bestLocation.getLongitude();
try {
//获取jpg文件
ExifInterface exif = new ExifInterface(filePath + / +filename);
//写入纬度信息
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, gpsInfoConvert(lat));
exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF,
lat > 0 ?N : S);
//写入经度信息
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, gpsInfoConvert(lon));
exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF,
lon > 0 ?E : W);
//这句话很重要,一定要saveAttributes才能使写入的信息生效。
exif.saveAttributes();
//获取纬度信息
String latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
//获取经度信息
String longitude = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
} catch (IOException e) {
e.printStackTrace();
}
/*
* TAG_DATETIME 时间日期
* TAG_FLASH 闪光灯
* TAG_GPS_LATITUDE 纬度
* TAG_GPS_LATITUDE_REF 纬度参考
* TAG_GPS_LONGITUDE 经度
* TAG_GPS_LONGITUDE_REF 经度参考
* TAG_IMAGE_LENGTH 图片长
* TAG_IMAGE_WIDTH 图片宽
* TAG_MAKE 设备制造商
* TAG_MODEL 设备型号
* TAG_ORIENTATION 方向
* TAG_WHITE_BALANCE 白平衡
*/
public static String readPicturedDate(String photoPath) {
try {
if (!TextUtils.isEmpty(photoPath)) {
ExifInterface exifInterface = new ExifInterface(photoPath);
return exifInterface.getAttribute(ExifInterface.TAG_DATETIME);
}
} catch (Exception e) {
e.printStackTrace();
}
return new Date().toString();
}
public static float[] readPicturedPlace(String photoPath) {
float[] location = new float[2];
try {
if (!TextUtils.isEmpty(photoPath)) {
ExifInterface exifInterface = new ExifInterface(photoPath);
location[0] = toLatLng(exifInterface.getAttribute(ExifInterface.TAG_GPS_LATITUDE));
location[1] = toLatLng(exifInterface.getAttribute(ExifInterface.TAG_GPS_LONGITUDE));
return location;
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* 读取图片属性:旋转的角度
*
* @param path 图片绝对路径
* @return degree旋转的角度
* 在获取Bitmap时,获得旋转的角度,再进行相应的旋转操作就可以了。
*/
public static int readPictureDegree(String path) {
int degree = 0;
try {
if (TextUtils.isEmpty(path)) return degree;
ExifInterface exifInterface = new ExifInterface(path);
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degree = 270;
break;
}
} catch (IOException e) {
e.printStackTrace();
}
return degree;
}
public static float toLatLng(String dfm) {
String[] dfmArr = dfm.split(",");
if (dfmArr.length > 1) {
float d = (toLatLngSub(dfmArr[0]));
float f = toLatLngSub(dfmArr[1]);
float m = toLatLngSub(dfmArr[2]);
f = f + (m / 60);
return (f / 60) + (d);
}
return 0;
}
public static float toLatLngSub(String arg) {
String[] args = arg.split("/");
float a = Float.parseFloat(args[0]);
float b = Float.parseFloat(args[1]);
return a / b;
}