There are many questions like this, and of course I followed them, but did not get any success. I tried this , this and this . and is done as described. Here is what I am doing: InonActivityResult...()
ExifInterface exifInterface = null;
try {
exifInterface = new ExifInterface(filepathwithname+ ".Jpg");
MyGeoDegree myGeoDegree = new MyGeoDegree(exifInterface);
Log.i("LAT", String.valueOf(myGeoDegree.getLatitudeE6()));
Log.i("LNG",String.valueOf(myGeoDegree.getLongitudeE6()));
} catch (IOException e) {
e.printStackTrace();
}
also try only with the file name with the extension. and passed this exifInterface to this class (described in one of the links)
public class MyGeoDegree {
private boolean valid = false;
Float Latitude, Longitude;
public MyGeoDegree(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)) {
valid = true;
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 = new Double(stringD[0]);
Double D1 = new Double(stringD[1]);
Double FloatD = D0 / D1;
String[] stringM = DMS[1].split("/", 2);
Double M0 = new Double(stringM[0]);
Double M1 = new Double(stringM[1]);
Double FloatM = M0 / M1;
String[] stringS = DMS[2].split("/", 2);
Double S0 = new Double(stringS[0]);
Double S1 = new Double(stringS[1]);
Double FloatS = S0 / S1;
result = new Float(FloatD + (FloatM / 60) + (FloatS / 3600));
return result;
}
;
public boolean isValid() {
return valid;
}
@Override
public String toString() {
return (String.valueOf(Latitude)
+ ", "
+ String.valueOf(Longitude));
}
public int getLatitudeE6() {
return (int) (Latitude * 1000000);
}
public int getLongitudeE6() {
return (int) (Longitude * 1000000);
}
}
But getting this error in the log:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=null} to activity {com.whitefox.publicconnect/com.whitefox.publicconnect.LevelFirst}: java.lang.NullPointerException: Attempt to invoke virtual method 'float java.lang.Float.floatValue()' on a null object reference
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'float java.lang.Float.floatValue()' on a null object reference
11-19 13:20:28.695 19559-19559/com.whitefox.publicconnect E/AndroidRuntime: at loaction.MyGeoDegree.getLatitudeE6(MyGeoDegree.java:81)
source
share