-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(android) float variant of latitude/longitude exif data on android
- Loading branch information
Showing
4 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
android/src/main/java/com/reactnative/ivpusic/imagepicker/GeoDegree.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.reactnative.ivpusic.imagepicker; | ||
|
||
import android.media.ExifInterface; | ||
|
||
public class GeoDegree { | ||
Float latitude; | ||
Float longitude; | ||
|
||
public GeoDegree(ExifInterface exif) { | ||
String attrLATITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE); | ||
String attrLATITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF); | ||
String attrLONGITUDE = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE); | ||
String attrLONGITUDE_REF = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF); | ||
|
||
if ((attrLATITUDE != null) | ||
&& (attrLATITUDE_REF != null) | ||
&& (attrLONGITUDE != null) | ||
&& (attrLONGITUDE_REF != null)) { | ||
|
||
if (attrLATITUDE_REF.equals("N")) { | ||
latitude = convertToDegree(attrLATITUDE); | ||
} else { | ||
latitude = 0 - convertToDegree(attrLATITUDE); | ||
} | ||
|
||
if (attrLONGITUDE_REF.equals("E")) { | ||
longitude = convertToDegree(attrLONGITUDE); | ||
} else { | ||
longitude = 0 - convertToDegree(attrLONGITUDE); | ||
} | ||
} | ||
} | ||
|
||
private Float convertToDegree(String stringDMS) { | ||
Float result = null; | ||
String[] DMS = stringDMS.split(",", 3); | ||
|
||
String[] stringD = DMS[0].split("/", 2); | ||
Double D0 = Double.valueOf(stringD[0]); | ||
Double D1 = Double.valueOf(stringD[1]); | ||
double FloatD = D0 / D1; | ||
|
||
String[] stringM = DMS[1].split("/", 2); | ||
Double M0 = Double.valueOf(stringM[0]); | ||
Double M1 = Double.valueOf(stringM[1]); | ||
double FloatM = M0 / M1; | ||
|
||
String[] stringS = DMS[2].split("/", 2); | ||
Double S0 = Double.valueOf(stringS[0]); | ||
Double S1 = Double.valueOf(stringS[1]); | ||
double FloatS = S0 / S1; | ||
|
||
result = (float) (FloatD + (FloatM / 60) + (FloatS / 3600)); | ||
|
||
return result; | ||
} | ||
|
||
public Float getLatitude() { | ||
return latitude; | ||
} | ||
|
||
public Float getLongitude() { | ||
return longitude; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters