View Javadoc

1   package cz.cuni.amis.pogamut.usar2004.communication.messages.datatypes;
2   
3   /**
4    * ‘int’, ’double’, ’char’ provide the latitude degree, minute (as a decimal),
5    * and cardinal description (i.e. ‘N’ or ‘S’), respectively. There are only two
6    * possible values for the ‘char’ parameter: ‘N’ for North and ‘S’ for South.
7    *
8    * This class is used to store data from GPS sensor.
9    *
10   * @author vejmanm
11   */
12  public class Latitude extends GeographicCoordinates
13  {
14      public Latitude()
15      {
16      }
17  
18      public Latitude(int degree, double minute, char cardinal)
19      {
20          super(degree, minute, cardinal);
21      }
22  
23      /**
24       * Converter method for converting the degree, minute to minutes
25       * respectively to cardinal character.
26       *
27       * @param latitude Latitude to convert
28       * @return Returns minute representation of input latitude.
29       */
30      public static double DMCToMinutes(Latitude latitude)
31      {
32          double returnee = latitude.minute + latitude.degree * 60;
33          return (latitude.cardinal == 'S')?-returnee:returnee;
34      }
35  
36      /**
37       * Converter method for converting minutes to degree minutes and to
38       * determine cardinal character.
39       *
40       * @param minutes Minute representation of Latitude
41       * @return Returns latitude representation of input minutes.
42       */
43      public static Latitude MinutesTODMC(double minutes)
44      {
45          double minute = Math.abs(minutes % 60);
46          int degree = Math.abs((int) minutes / 60);
47          char cardinal = (minutes < 0)?'S':'N';
48          return new Latitude(degree, minute, cardinal);
49      }
50  
51      /**
52       * Converter method for converting the degree, minute to degrees
53       * respectively to cardinal character.
54       *
55       * @param latitude Latitude to convert
56       * @return Returns degree representation of input latitude.
57       */
58      public static double DMCToDegree(Latitude latitude)
59      {
60          double returnee = latitude.minute / 60d + latitude.degree;
61          return (latitude.getCardinal() == 'S')?-returnee:returnee;
62      }
63  
64      /**
65       * Converter method for converting degrees to degree minutes and to
66       * determine cardinal character.
67       *
68       * @param degree Degree representation of Latitude
69       * @return Returns latitude representation of input degrees.
70       */
71      public static Latitude DegreeToDMC(double degree)
72      {
73          int deg = (int) Math.abs(degree);
74          double minute = (Math.abs(degree) - deg) * 60;
75          char cardinal = (degree < 0)?'S':'N';
76          return new Latitude(deg, minute, cardinal);
77      }
78  }