summaryrefslogtreecommitdiffstats
path: root/media/java
diff options
context:
space:
mode:
authorWu-cheng Li <wuchengli@google.com>2010-05-20 17:38:21 +0800
committerWu-cheng Li <wuchengli@google.com>2010-05-27 15:59:05 +0800
commitc109190b6984da6cba4cea44a0304b6da12d77e6 (patch)
tree2ef51852fa763a8df8a9e980e4fef127c190546f /media/java
parentdf0364de6f7be68e003729c262fe2731b82ae10e (diff)
downloadframeworks_base-c109190b6984da6cba4cea44a0304b6da12d77e6.zip
frameworks_base-c109190b6984da6cba4cea44a0304b6da12d77e6.tar.gz
frameworks_base-c109190b6984da6cba4cea44a0304b6da12d77e6.tar.bz2
Add support for gps altitude EXIF tags.
Also improve the precision of getLatLong(). Change-Id: Id2c60f0d1d19e9da173b5ec1228f03c2195e189f
Diffstat (limited to 'media/java')
-rw-r--r--media/java/android/media/ExifInterface.java40
1 files changed, 35 insertions, 5 deletions
diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java
index b26906d..74488c5 100644
--- a/media/java/android/media/ExifInterface.java
+++ b/media/java/android/media/ExifInterface.java
@@ -51,6 +51,19 @@ public class ExifInterface {
public static final String TAG_GPS_LATITUDE_REF = "GPSLatitudeRef";
/** Type is String. */
public static final String TAG_GPS_LONGITUDE_REF = "GPSLongitudeRef";
+
+ /**
+ * The altitude (in meters) based on the reference in TAG_GPS_ALTITUDE_REF.
+ * Type is rational.
+ */
+ public static final String TAG_GPS_ALTITUDE = "GPSAltitude";
+
+ /**
+ * 0 if the altitude is above sea level. 1 if the altitude is below sea
+ * level. Type is int.
+ */
+ public static final String TAG_GPS_ALTITUDE_REF = "GPSAltitudeRef";
+
/** Type is String. */
public static final String TAG_GPS_TIMESTAMP = "GPSTimeStamp";
/** Type is String. */
@@ -289,6 +302,23 @@ public class ExifInterface {
}
/**
+ * Return the altitude in meters. If the exif tag does not exist, return
+ * <var>defaultValue</var>.
+ *
+ * @param defaultValue the value to return if the tag is not available.
+ */
+ public double getAltitude(double defaultValue) {
+ double altitude = getAttributeDouble(TAG_GPS_ALTITUDE, -1);
+ int ref = getAttributeInt(TAG_GPS_ALTITUDE_REF, -1);
+
+ if (altitude >= 0 && ref >= 0) {
+ return (double) (altitude * ((ref == 1) ? -1 : 1));
+ } else {
+ return defaultValue;
+ }
+ }
+
+ /**
* Returns number of milliseconds since Jan. 1, 1970, midnight.
* Returns -1 if the date time information if not available.
* @hide
@@ -345,14 +375,14 @@ public class ExifInterface {
/ Float.parseFloat(pair[1].trim())));
pair = parts[2].split("/");
- float seconds = Float.parseFloat(pair[0].trim())
- / Float.parseFloat(pair[1].trim());
+ double seconds = Double.parseDouble(pair[0].trim())
+ / Double.parseDouble(pair[1].trim());
- float result = degrees + (minutes / 60F) + (seconds / (60F * 60F));
+ double result = degrees + (minutes / 60.0) + (seconds / 3600.0);
if ((ref.equals("S") || ref.equals("W"))) {
- return -result;
+ return (float) -result;
}
- return result;
+ return (float) result;
} catch (RuntimeException ex) {
// if for whatever reason we can't parse the lat long then return
// null