mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Flip lat long values around for XY coords
This commit is contained in:
parent
ffe967b623
commit
3432ffeae2
2 changed files with 40 additions and 6 deletions
|
|
@ -15,7 +15,7 @@ public class GPSExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Extract GPS coords of image
|
//Extract GPS coords of image
|
||||||
public String getCoords() {
|
public String getCoords(boolean xyCoordsReq) {
|
||||||
|
|
||||||
ExifInterface exif;
|
ExifInterface exif;
|
||||||
String latitude = "";
|
String latitude = "";
|
||||||
|
|
@ -23,6 +23,7 @@ public class GPSExtractor {
|
||||||
String latitude_ref = "";
|
String latitude_ref = "";
|
||||||
String longitude_ref = "";
|
String longitude_ref = "";
|
||||||
String decimalCoords = "";
|
String decimalCoords = "";
|
||||||
|
String xyCoords = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exif = new ExifInterface(filePath);
|
exif = new ExifInterface(filePath);
|
||||||
|
|
@ -45,11 +46,17 @@ public class GPSExtractor {
|
||||||
Log.d("Image", "Longitude: " + longitude + " " + longitude_ref);
|
Log.d("Image", "Longitude: " + longitude + " " + longitude_ref);
|
||||||
|
|
||||||
decimalCoords = getDecimalCoords(latitude, latitude_ref, longitude, longitude_ref);
|
decimalCoords = getDecimalCoords(latitude, latitude_ref, longitude, longitude_ref);
|
||||||
return decimalCoords;
|
xyCoords = getXyCoords(latitude, latitude_ref, longitude, longitude_ref);
|
||||||
|
|
||||||
|
if (xyCoordsReq = true) {
|
||||||
|
return xyCoords;
|
||||||
|
} else {
|
||||||
|
return decimalCoords;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Converts format of coords into decimal coords as required by API for next step
|
//Converts format of coords into decimal coords as required by MediaWiki API
|
||||||
private String getDecimalCoords(String latitude, String latitude_ref, String longitude, String longitude_ref) {
|
private String getDecimalCoords(String latitude, String latitude_ref, String longitude, String longitude_ref) {
|
||||||
|
|
||||||
double decLatitude, decLongitude;
|
double decLatitude, decLongitude;
|
||||||
|
|
@ -68,10 +75,37 @@ public class GPSExtractor {
|
||||||
decLongitude = 0 - convertToDegree(longitude);
|
decLongitude = 0 - convertToDegree(longitude);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Have to return Longitude before Latitude for X/Y conversion. Long = X; Lat = Y
|
String decimalCoords = String.valueOf(decLatitude) + "|" + String.valueOf(decLongitude);
|
||||||
return (String.valueOf(decLongitude) + "|" + String.valueOf(decLatitude));
|
Log.d("Coords", "Latitude and Longitude are " + decimalCoords);
|
||||||
|
return decimalCoords;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Converts format of coords into XY values as required by Quadtree for caching
|
||||||
|
private String getXyCoords(String latitude, String latitude_ref, String longitude, String longitude_ref) {
|
||||||
|
|
||||||
|
double 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Have to return Longitude before Latitude for X/Y conversion. Long = X; Lat = Y
|
||||||
|
String xyCoords = String.valueOf(decLongitude) + "|" + String.valueOf(decLatitude);
|
||||||
|
Log.d("Coords", "X and Y are " + xyCoords);
|
||||||
|
return xyCoords;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private double convertToDegree(String stringDMS){
|
private double convertToDegree(String stringDMS){
|
||||||
double result;
|
double result;
|
||||||
String[] DMS = stringDMS.split(",", 3);
|
String[] DMS = stringDMS.split(",", 3);
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ public class ShareActivity
|
||||||
//extract the coordinates of image in decimal degrees
|
//extract the coordinates of image in decimal degrees
|
||||||
Log.d("Image", "Calling GPSExtractor");
|
Log.d("Image", "Calling GPSExtractor");
|
||||||
GPSExtractor imageObj = new GPSExtractor(filePath);
|
GPSExtractor imageObj = new GPSExtractor(filePath);
|
||||||
String coords = imageObj.getCoords();
|
String coords = imageObj.getCoords(false);
|
||||||
|
|
||||||
if (coords != null) {
|
if (coords != null) {
|
||||||
Log.d("Image", "Coords of image in Long/Lat: " + coords);
|
Log.d("Image", "Coords of image in Long/Lat: " + coords);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue