目前Android SDK定义的Tag有:
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 白平衡
String sFileName="/sdcard/DCIM/Camera/1.JPG";
try{
ExifInterface exif = new ExifInterface(sFileName);
String sModel=exif.getAttribute(ExifInterface.TAG_MODEL);
Toast.makeText(PhotoCatActivity.this,"1.JPG Exif:"+sModel, Toast.LENGTH_SHORT).show();
} catch(Exception ee){ }
经纬度得到的数据格式是 "num1/denom1,num2/denom2,num3/denom3",如何得到真正的经纬度呢?
public Location exif2Loc(String flNm) {
String sLat = "", sLatR = "", sLon = "", sLonR = "";
try {
ExifInterface ef = new ExifInterface(flNm);
sLat = ef.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
sLon = ef.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
sLatR = ef.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
sLonR = ef.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
} catch (IOException e) {return null;} double lat = dms2Dbl(sLat);
if (lat > 180.0) return null;
double lon = dms2Dbl(sLon);
if (lon > 180.0) return null; lat = sLatR.contains("S") ? -lat : lat;
lon = sLonR.contains("W") ? -lon : lon; Location loc = new Location("exif");
loc.setLatitude(lat);
loc.setLongitude(lon);
return loc;
} //-------------------------------------------------------------------------
double dms2Dbl(String sDMS){
double dRV = 999.0;
try {
String[] DMSs = sDMS.split(",", 3);
String s[] = DMSs[0].split("/", 2);
dRV = (new Double(s[0])/new Double(s[1]));
s = DMSs[1].split("/", 2);
dRV += ((new Double(s[0])/new Double(s[1]))/60);
s = DMSs[2].split("/", 2);
dRV += ((new Double(s[0])/new Double(s[1]))/3600);
} catch (Exception e) {}
return dRV;
}
如何根据经纬度得到具体的地址?
public final String getAddress(double latitude, double longitude) {
Geocoder gc = new Geocoder(this, Locale.getDefault());
StringBuilder sb = new StringBuilder();
try {
List add = gc.getFromLocation(latitude, longitude, 1);
if (add.size() > 0) {
Address ad = add.get(0);
sb.append(ad.getAddressLine(0));
sb.append(ad.getAddressLine(1));
sb.append(ad.getAddressLine(2));
}
} catch (Exception e) { }
return sb.toString();
}