aboutsummaryrefslogtreecommitdiffstats
path: root/libs/android-transcoder/src/main/java/net/ypresto/androidtranscoder/utils
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-01-07 20:28:07 +0100
committerChristian Schneppe <christian@pix-art.de>2019-01-07 20:28:07 +0100
commit39c37184f126c2f3cada5d824fbd7b2ab7ee5d19 (patch)
tree7b0fd1b57f75696a8185a2c355fbcf785f225560 /libs/android-transcoder/src/main/java/net/ypresto/androidtranscoder/utils
parent7685c46c5af7154c6fb59ab020a174923643bd48 (diff)
update androidTranscoder to version 0.3
Diffstat (limited to 'libs/android-transcoder/src/main/java/net/ypresto/androidtranscoder/utils')
-rw-r--r--libs/android-transcoder/src/main/java/net/ypresto/androidtranscoder/utils/ISO6709LocationParser.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/libs/android-transcoder/src/main/java/net/ypresto/androidtranscoder/utils/ISO6709LocationParser.java b/libs/android-transcoder/src/main/java/net/ypresto/androidtranscoder/utils/ISO6709LocationParser.java
new file mode 100644
index 000000000..273007d3c
--- /dev/null
+++ b/libs/android-transcoder/src/main/java/net/ypresto/androidtranscoder/utils/ISO6709LocationParser.java
@@ -0,0 +1,37 @@
+package net.ypresto.androidtranscoder.utils;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class ISO6709LocationParser {
+ private final Pattern pattern;
+
+ public ISO6709LocationParser() {
+ this.pattern = Pattern.compile("([+\\-][0-9.]+)([+\\-][0-9.]+)");
+ }
+
+ /**
+ * This method parses the given string representing a geographic point location by coordinates in ISO 6709 format
+ * and returns the latitude and the longitude in float. If <code>location</code> is not in ISO 6709 format,
+ * this method returns <code>null</code>
+ *
+ * @param location a String representing a geographic point location by coordinates in ISO 6709 format
+ * @return <code>null</code> if the given string is not as expected, an array of floats with size 2,
+ * where the first element represents latitude and the second represents longitude, otherwise.
+ */
+ public float[] parse(String location) {
+ if (location == null) return null;
+ Matcher m = pattern.matcher(location);
+ if (m.find() && m.groupCount() == 2) {
+ String latstr = m.group(1);
+ String lonstr = m.group(2);
+ try {
+ float lat = Float.parseFloat(latstr);
+ float lon = Float.parseFloat(lonstr);
+ return new float[]{lat, lon};
+ } catch (NumberFormatException ignored) {
+ }
+ }
+ return null;
+ }
+}