aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/cgBase.java
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2011-09-15 14:59:42 +0200
committerSamuel Tardieu <sam@rfc1149.net>2011-09-15 15:14:49 +0200
commit880f483c345b687181027f0e0074ec4461039ba2 (patch)
treedbfcd909881065057de4fcc296bd92ce6002bbbe /src/cgeo/geocaching/cgBase.java
parent42b8d8542e4056ece23af2ff8ee2b5db8abe832b (diff)
downloadcgeo-880f483c345b687181027f0e0074ec4461039ba2.zip
cgeo-880f483c345b687181027f0e0074ec4461039ba2.tar.gz
cgeo-880f483c345b687181027f0e0074ec4461039ba2.tar.bz2
Use GeopointParser to parse coordinates
Diffstat (limited to 'src/cgeo/geocaching/cgBase.java')
-rw-r--r--src/cgeo/geocaching/cgBase.java112
1 files changed, 0 insertions, 112 deletions
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java
index c1ef6b8..53227e5 100644
--- a/src/cgeo/geocaching/cgBase.java
+++ b/src/cgeo/geocaching/cgBase.java
@@ -2480,118 +2480,6 @@ public class cgBase {
return formatLatitude(coords.getLatitude(), degrees) + " | " + formatLongitude(coords.getLongitude(), degrees);
}
- // TODO Use android.util.Pair<Double, String> if needed rather than a Map here.
- public static Map<String, Object> parseCoordinate(String coord, String latlon) {
- final Map<String, Object> coords = new HashMap<String, Object>();
-
- final Pattern patternA = Pattern.compile("^([NSWE])[^\\d]*(\\d+)°? +(\\d+)([\\.|,](\\d+))?$", Pattern.CASE_INSENSITIVE);
- final Pattern patternB = Pattern.compile("^([NSWE])[^\\d]*(\\d+)([\\.|,](\\d+))?$", Pattern.CASE_INSENSITIVE);
- final Pattern patternC = Pattern.compile("^(-?\\d+)([\\.|,](\\d+))?$", Pattern.CASE_INSENSITIVE);
- final Pattern patternD = Pattern.compile("^([NSWE])[^\\d]*(\\d+)°?$", Pattern.CASE_INSENSITIVE);
- final Pattern patternE = Pattern.compile("^(-?\\d+)°?$", Pattern.CASE_INSENSITIVE);
- final Pattern patternF = Pattern.compile("^([NSWE])[^\\d]*(\\d+)$", Pattern.CASE_INSENSITIVE);
- final Pattern pattern0 = Pattern.compile("^(-?\\d+)([\\.|,](\\d+))?$", Pattern.CASE_INSENSITIVE);
-
- coord = coord.trim().toUpperCase();
-
- final Matcher matcherA = patternA.matcher(coord);
- final Matcher matcherB = patternB.matcher(coord);
- final Matcher matcherC = patternC.matcher(coord);
- final Matcher matcherD = patternD.matcher(coord);
- final Matcher matcherE = patternE.matcher(coord);
- final Matcher matcherF = patternF.matcher(coord);
- final Matcher matcher0 = pattern0.matcher(coord);
-
- int latlonNegative;
- if (matcherA.find() && matcherA.groupCount() > 0) {
- if (matcherA.group(1).equalsIgnoreCase("N") || matcherA.group(1).equalsIgnoreCase("E")) {
- latlonNegative = 1;
- } else {
- latlonNegative = -1;
- }
-
- if (matcherA.groupCount() < 5 || matcherA.group(5) == null) {
- coords.put("coordinate", Double.valueOf(latlonNegative * (Double.valueOf(matcherA.group(2)) + Double.valueOf(matcherA.group(3) + ".0") / 60)));
- coords.put("string", matcherA.group(1) + " " + matcherA.group(2) + "° " + matcherA.group(3) + ".000");
- } else {
- coords.put("coordinate", Double.valueOf(latlonNegative * (Double.valueOf(matcherA.group(2)) + Double.valueOf(matcherA.group(3) + "." + matcherA.group(5)) / 60)));
- coords.put("string", matcherA.group(1) + " " + matcherA.group(2) + "° " + matcherA.group(3) + "." + matcherA.group(5));
- }
-
- return coords;
- } else if (matcherB.find() && matcherB.groupCount() > 0) {
- if (matcherB.group(1).equalsIgnoreCase("N") || matcherB.group(1).equalsIgnoreCase("E")) {
- latlonNegative = 1;
- } else {
- latlonNegative = -1;
- }
-
- if (matcherB.groupCount() < 4 || matcherB.group(4) == null) {
- coords.put("coordinate", Double.valueOf(latlonNegative * (Double.valueOf(matcherB.group(2) + ".0"))));
- } else {
- coords.put("coordinate", Double.valueOf(latlonNegative * (Double.valueOf(matcherB.group(2) + "." + matcherB.group(4)))));
- }
- } else if (matcherC.find() && matcherC.groupCount() > 0) {
- if (matcherC.groupCount() < 3 || matcherC.group(3) == null) {
- coords.put("coordinate", Double.valueOf(new Float(matcherC.group(1) + ".0")));
- } else {
- coords.put("coordinate", Double.valueOf(new Float(matcherC.group(1) + "." + matcherC.group(3))));
- }
- } else if (matcherD.find() && matcherD.groupCount() > 0) {
- if (matcherD.group(1).equalsIgnoreCase("N") || matcherD.group(1).equalsIgnoreCase("E")) {
- latlonNegative = 1;
- } else {
- latlonNegative = -1;
- }
-
- coords.put("coordinate", Double.valueOf(latlonNegative * (Double.valueOf(matcherB.group(2)))));
- } else if (matcherE.find() && matcherE.groupCount() > 0) {
- coords.put("coordinate", Double.valueOf(matcherE.group(1)));
- } else if (matcherF.find() && matcherF.groupCount() > 0) {
- if (matcherF.group(1).equalsIgnoreCase("N") || matcherF.group(1).equalsIgnoreCase("E")) {
- latlonNegative = 1;
- } else {
- latlonNegative = -1;
- }
-
- coords.put("coordinate", Double.valueOf(latlonNegative * (Double.valueOf(matcherB.group(2)))));
- } else {
- return null;
- }
-
- if (matcher0.find() && matcher0.groupCount() > 0) {
- String tmpDir = null;
- Float tmpCoord;
- if (matcher0.groupCount() < 3 || matcher0.group(3) == null) {
- tmpCoord = new Float("0.0");
- } else {
- tmpCoord = new Float("0." + matcher0.group(3));
- }
-
- if (latlon.equalsIgnoreCase("lat")) {
- if (matcher0.group(1).equals("+")) {
- tmpDir = "N";
- }
- if (matcher0.group(1).equals("-")) {
- tmpDir = "S";
- }
- } else if (latlon.equalsIgnoreCase("lon")) {
- if (matcher0.group(1).equals("+")) {
- tmpDir = "E";
- }
- if (matcher0.group(1).equals("-")) {
- tmpDir = "W";
- }
- }
-
- coords.put("string", tmpDir + " " + matcher0.group(1) + "° " + (Math.round(tmpCoord / (1 / 60) * 1000) * 1000));
-
- return coords;
- } else {
- return new HashMap<String, Object>();
- }
- }
-
public UUID searchByNextPage(cgSearchThread thread, final UUID searchId, int reason, boolean showCaptcha) {
final String[] viewstates = app.getViewstates(searchId);