Add support for gps altitude EXIF tags.

Also improve the precision of getLatLong().

Change-Id: Id2c60f0d1d19e9da173b5ec1228f03c2195e189f
This commit is contained in:
Wu-cheng Li
2010-05-20 17:38:21 +08:00
parent df0364de6f
commit c109190b69
2 changed files with 70 additions and 5 deletions

View File

@ -87263,6 +87263,19 @@
<exception name="IOException" type="java.io.IOException">
</exception>
</constructor>
<method name="getAltitude"
return="double"
abstract="false"
native="false"
synchronized="false"
static="false"
final="false"
deprecated="not deprecated"
visibility="public"
>
<parameter name="defaultValue" type="double">
</parameter>
</method>
<method name="getAttribute"
return="java.lang.String"
abstract="false"
@ -87501,6 +87514,28 @@
visibility="public"
>
</field>
<field name="TAG_GPS_ALTITUDE"
type="java.lang.String"
transient="false"
volatile="false"
value="&quot;GPSAltitude&quot;"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="TAG_GPS_ALTITUDE_REF"
type="java.lang.String"
transient="false"
volatile="false"
value="&quot;GPSAltitudeRef&quot;"
static="true"
final="true"
deprecated="not deprecated"
visibility="public"
>
</field>
<field name="TAG_GPS_DATESTAMP"
type="java.lang.String"
transient="false"

View File

@ -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. */
@ -288,6 +301,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.
@ -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