Merge "Improved conversion accuracy of exif geotag data" into honeycomb

This commit is contained in:
Wu-cheng Li
2011-01-24 18:48:34 -08:00
committed by Android (Google) Code Review

View File

@ -299,14 +299,18 @@ public class ExifInterface {
String lngRef = mAttributes.get(ExifInterface.TAG_GPS_LONGITUDE_REF); String lngRef = mAttributes.get(ExifInterface.TAG_GPS_LONGITUDE_REF);
if (latValue != null && latRef != null && lngValue != null && lngRef != null) { if (latValue != null && latRef != null && lngValue != null && lngRef != null) {
try {
output[0] = convertRationalLatLonToFloat(latValue, latRef); output[0] = convertRationalLatLonToFloat(latValue, latRef);
output[1] = convertRationalLatLonToFloat(lngValue, lngRef); output[1] = convertRationalLatLonToFloat(lngValue, lngRef);
return true; return true;
} else { } catch (IllegalArgumentException e) {
return false; // if values are not parseable
} }
} }
return false;
}
/** /**
* Return the altitude in meters. If the exif tag does not exist, return * Return the altitude in meters. If the exif tag does not exist, return
* <var>defaultValue</var>. * <var>defaultValue</var>.
@ -373,12 +377,12 @@ public class ExifInterface {
String [] pair; String [] pair;
pair = parts[0].split("/"); pair = parts[0].split("/");
int degrees = (int) (Float.parseFloat(pair[0].trim()) double degrees = Double.parseDouble(pair[0].trim())
/ Float.parseFloat(pair[1].trim())); / Double.parseDouble(pair[1].trim());
pair = parts[1].split("/"); pair = parts[1].split("/");
int minutes = (int) ((Float.parseFloat(pair[0].trim()) double minutes = Double.parseDouble(pair[0].trim())
/ Float.parseFloat(pair[1].trim()))); / Double.parseDouble(pair[1].trim());
pair = parts[2].split("/"); pair = parts[2].split("/");
double seconds = Double.parseDouble(pair[0].trim()) double seconds = Double.parseDouble(pair[0].trim())
@ -389,10 +393,12 @@ public class ExifInterface {
return (float) -result; return (float) -result;
} }
return (float) result; return (float) result;
} catch (RuntimeException ex) { } catch (NumberFormatException e) {
// if for whatever reason we can't parse the lat long then return // Some of the nubmers are not valid
// null throw new IllegalArgumentException();
return 0f; } catch (ArrayIndexOutOfBoundsException e) {
// Some of the rational does not follow the correct format
throw new IllegalArgumentException();
} }
} }