Skip to content

Commit

Permalink
(android) float variant of latitude/longitude exif data on android
Browse files Browse the repository at this point in the history
  • Loading branch information
ivpusic committed May 4, 2021
1 parent e311caa commit 9d86ade
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ static WritableMap extract(String path) throws IOException {

ExifInterface exif = new ExifInterface(path);

GeoDegree geoDegree = new GeoDegree(exif);
if (geoDegree.getLatitude() != null && geoDegree.getLongitude() != null) {
exifData.putDouble("Latitude", geoDegree.getLatitude());
exifData.putDouble("Longitude", geoDegree.getLongitude());
}

for (String attribute : attributes) {
String value = exif.getAttribute(attribute);
exifData.putString(attribute, value);
Expand Down
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;
}
}
2 changes: 2 additions & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location.gps" />

<application
android:name=".MainApplication"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-image-crop-picker",
"version": "0.36.0",
"version": "0.36.1",
"description": "Select single or multiple images, with cropping option",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 9d86ade

Please sign in to comment.