mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43:54 +01:00
Added decimal coord conversion
This commit is contained in:
parent
131b9815af
commit
7804546ae3
2 changed files with 56 additions and 7 deletions
|
|
@ -24,6 +24,7 @@ public class ImageProcessing {
|
|||
this.uri = uri;
|
||||
}
|
||||
|
||||
//Gets file path of image from its Uri
|
||||
public String getFilePath(){
|
||||
String filePath ="";
|
||||
// Will return "image:x*"
|
||||
|
|
@ -49,13 +50,15 @@ public class ImageProcessing {
|
|||
return filePath;
|
||||
}
|
||||
|
||||
|
||||
//Extract GPS coords of image
|
||||
public String getCoords(String filePath) {
|
||||
|
||||
ExifInterface exif;
|
||||
String latitude = "";
|
||||
String longitude = "";
|
||||
String latitude_ref = "";
|
||||
String longitude_ref = "";
|
||||
ExifInterface exif;
|
||||
String decimalCoords = "";
|
||||
|
||||
try {
|
||||
exif = new ExifInterface(filePath);
|
||||
|
|
@ -67,10 +70,58 @@ public class ImageProcessing {
|
|||
Log.d("Image", "Latitude: " + latitude + " " + latitude_ref);
|
||||
Log.d("Image", "Longitude: " + longitude + " " + longitude_ref);
|
||||
|
||||
decimalCoords = getDecimalCoords(latitude, latitude_ref, longitude, longitude_ref);
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.w("Image", e);
|
||||
}
|
||||
return latitude;
|
||||
return decimalCoords;
|
||||
}
|
||||
|
||||
//Converts format of coords into decimal coords as required by API for next step
|
||||
private String getDecimalCoords(String latitude, String latitude_ref, String longitude, String longitude_ref) {
|
||||
|
||||
Float decLatitude, decLongitude;
|
||||
|
||||
if(latitude_ref.equals("N")){
|
||||
decLatitude = convertToDegree(latitude);
|
||||
}
|
||||
else{
|
||||
decLatitude = 0 - convertToDegree(latitude);
|
||||
}
|
||||
|
||||
if(longitude_ref.equals("E")){
|
||||
decLongitude = convertToDegree(longitude);
|
||||
}
|
||||
else{
|
||||
decLongitude = 0 - convertToDegree(longitude);
|
||||
}
|
||||
|
||||
return (String.valueOf(decLatitude) + ", " + String.valueOf(decLongitude));
|
||||
}
|
||||
|
||||
private Float convertToDegree(String stringDMS){
|
||||
Float result;
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -187,10 +187,8 @@ public class ShareActivity
|
|||
|
||||
ImageProcessing imageObj = new ImageProcessing(this, mediaUri);
|
||||
String filePath = imageObj.getFilePath();
|
||||
String latitude = imageObj.getCoords(filePath);
|
||||
|
||||
|
||||
|
||||
String coords = imageObj.getCoords(filePath);
|
||||
Log.d(TAG, "Coords of image: " + coords);
|
||||
|
||||
|
||||
ImageLoader.getInstance().displayImage(mediaUriString, backgroundImageView);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue