aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/geopoint/Geopoint.java27
-rw-r--r--main/src/cgeo/geocaching/geopoint/GeopointParser.java4
2 files changed, 29 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java
index c718a5f..1655343 100644
--- a/main/src/cgeo/geocaching/geopoint/Geopoint.java
+++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java
@@ -572,4 +572,31 @@ public final class Geopoint implements ICoordinates, Parcelable {
return angdeg * DEG_TO_RAD;
}
+ /**
+ * Check whether a latitude built from user supplied data is valid. We accept both N90/S90.
+ *
+ * @return <tt>true</tt> if the latitude looks valid, <tt>false</tt> otherwise
+ */
+ public static boolean isValidLatitude(final double latitude) {
+ return latitude >= -90 && latitude <= 90;
+ }
+
+ /**
+ * Check whether a lo bngitudeuilt from user supplied data is valid. We accept both E180/W180.
+ *
+ * @return <tt>true</tt> if the longitude looks valid, <tt>false</tt> otherwise
+ */
+ public static boolean isValidLongitude(final double longitude) {
+ return longitude >= -180 && longitude <= 180;
+ }
+
+ /**
+ * Check whether a geopoint built from user supplied data is valid. We accept both N90/S90 and E180/W180.
+ *
+ * @return <tt>true</tt> if the geopoint looks valid, <tt>false</tt> otherwise
+ */
+ public boolean isValid() {
+ return isValidLatitude(latitude) && isValidLongitude(longitude);
+ }
+
}
diff --git a/main/src/cgeo/geocaching/geopoint/GeopointParser.java b/main/src/cgeo/geocaching/geopoint/GeopointParser.java
index 2809598..b486f01 100644
--- a/main/src/cgeo/geocaching/geopoint/GeopointParser.java
+++ b/main/src/cgeo/geocaching/geopoint/GeopointParser.java
@@ -66,10 +66,10 @@ class GeopointParser {
final double lat = latitudeWrapper.result;
final double lon = longitudeWrapper.result;
- if (lat > 90 || lat < -90) {
+ if (!Geopoint.isValidLatitude(lat)) {
throw new Geopoint.ParseException(text, LatLon.LAT);
}
- if (lon > 180 || lon < -180) {
+ if (!Geopoint.isValidLongitude(lon)) {
throw new Geopoint.ParseException(text, LatLon.LON);
}
return new Geopoint(lat, lon);