11package com .mapbox .services .commons .models ;
22
3+ import com .mapbox .services .Constants ;
4+
5+ import java .util .logging .Logger ;
6+
37/**
48 * Represents a position defined by a longitude, latitude, and optionally, an altitude.
59 *
610 * @since 1.0.0
711 */
812public class Position {
913
14+ private static final Logger logger = Logger .getLogger (Position .class .getSimpleName ());
15+
1016 private final double longitude ;
1117 private final double latitude ;
1218 private final double altitude ;
1319
1420 /**
15- * Private Constructor
21+ * Private constructor. It'll emit a warning if either latitude or longitude seem
22+ * to be out of range.
1623 *
1724 * @param longitude double value with position's longitude.
1825 * @param latitude double value with position's latitude.
@@ -23,6 +30,22 @@ private Position(double longitude, double latitude, double altitude) {
2330 this .longitude = longitude ;
2431 this .latitude = latitude ;
2532 this .altitude = altitude ;
33+
34+ if (latitude < -90 || latitude > 90 ) {
35+ // Checks the latitude value is within range or provide a warning otherwise
36+ logger .warning (String .format (Constants .DEFAULT_LOCALE ,
37+ "Latitude value seems to be out of range (found: %f, expected: [-90, 90]). "
38+ + "Did you accidentally reverse the longitude/latitude order?" ,
39+ latitude ));
40+ }
41+
42+ if (longitude < -180 || longitude > 180 ) {
43+ // Checks the longitude value is within range or provide a warning otherwise
44+ logger .warning (String .format (Constants .DEFAULT_LOCALE ,
45+ "Longitude value seems to be out of range (found: %f, expected: [-180, 180]). "
46+ + "Did you accidentally reverse the longitude/latitude order?" ,
47+ longitude ));
48+ }
2649 }
2750
2851 /**
@@ -103,6 +126,20 @@ public static Position fromCoordinates(double[] coordinates) {
103126 }
104127 }
105128
129+ /**
130+ * Builds a {@link Position} from a double longitude and latitude. Identical to
131+ * {@link #fromCoordinates(double, double)} but more explicit about the right order
132+ * for the longitude and latitude parameters.
133+ *
134+ * @param longitude double longitude value.
135+ * @param latitude double latitude value.
136+ * @return {@link Position}.
137+ * @since 2.0.0
138+ */
139+ public static Position fromLngLat (double longitude , double latitude ) {
140+ return Position .fromCoordinates (longitude , latitude );
141+ }
142+
106143 /**
107144 * Checks if a position has an altitude value.
108145 *
0 commit comments