mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 04:43: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
|
||||
public String getCoords() {
|
||||
public String getCoords(boolean xyCoordsReq) {
|
||||
|
||||
ExifInterface exif;
|
||||
String latitude = "";
|
||||
|
|
@ -23,6 +23,7 @@ public class GPSExtractor {
|
|||
String latitude_ref = "";
|
||||
String longitude_ref = "";
|
||||
String decimalCoords = "";
|
||||
String xyCoords = "";
|
||||
|
||||
try {
|
||||
exif = new ExifInterface(filePath);
|
||||
|
|
@ -45,11 +46,17 @@ public class GPSExtractor {
|
|||
Log.d("Image", "Longitude: " + 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) {
|
||||
|
||||
double decLatitude, decLongitude;
|
||||
|
|
@ -68,10 +75,37 @@ public class GPSExtractor {
|
|||
decLongitude = 0 - convertToDegree(longitude);
|
||||
}
|
||||
|
||||
//Have to return Longitude before Latitude for X/Y conversion. Long = X; Lat = Y
|
||||
return (String.valueOf(decLongitude) + "|" + String.valueOf(decLatitude));
|
||||
String decimalCoords = String.valueOf(decLatitude) + "|" + String.valueOf(decLongitude);
|
||||
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){
|
||||
double result;
|
||||
String[] DMS = stringDMS.split(",", 3);
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ public class ShareActivity
|
|||
//extract the coordinates of image in decimal degrees
|
||||
Log.d("Image", "Calling GPSExtractor");
|
||||
GPSExtractor imageObj = new GPSExtractor(filePath);
|
||||
String coords = imageObj.getCoords();
|
||||
String coords = imageObj.getCoords(false);
|
||||
|
||||
if (coords != null) {
|
||||
Log.d("Image", "Coords of image in Long/Lat: " + coords);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue