org.gavaghan.geodesy
Class GlobalCoordinates

java.lang.Object
  extended by org.gavaghan.geodesy.GlobalCoordinates
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<GlobalCoordinates>
Direct Known Subclasses:
GlobalPosition

public class GlobalCoordinates
extends java.lang.Object
implements java.lang.Comparable<GlobalCoordinates>, java.io.Serializable

Encapsulation of latitude and longitude coordinates on a globe. Negative latitude is southern hemisphere. Negative longitude is western hemisphere.

Any angle may be specified for longtiude and latitude, but all angles will be canonicalized such that:

 -90 <= latitude <= +90 - 180 < longitude <= +180
 

Author:
Mike Gavaghan
See Also:
Serialized Form

Constructor Summary
GlobalCoordinates(double latitude, double longitude)
          Construct a new GlobalCoordinates.
 
Method Summary
 int compareTo(GlobalCoordinates other)
          Compare these coordinates to another set of coordiates.
 boolean equals(java.lang.Object obj)
          Compare these coordinates to another object for equality.
 double getLatitude()
          Get latitude.
 double getLongitude()
          Get longitude.
 int hashCode()
          Get a hash code for these coordinates.
 void setLatitude(double latitude)
          Set latitude.
 void setLongitude(double longitude)
          Set longitude.
 java.lang.String toString()
          Get coordinates as a string.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GlobalCoordinates

public GlobalCoordinates(double latitude,
                         double longitude)
Construct a new GlobalCoordinates. Angles will be canonicalized.

Parameters:
latitude - latitude in degrees
longitude - longitude in degrees
Method Detail

getLatitude

public double getLatitude()
Get latitude.

Returns:
latitude in degrees

setLatitude

public void setLatitude(double latitude)
Set latitude. The latitude value will be canonicalized (which might result in a change to the longitude). Negative latitude is southern hemisphere.

Parameters:
latitude - in degrees

getLongitude

public double getLongitude()
Get longitude.

Returns:
longitude in degrees

setLongitude

public void setLongitude(double longitude)
Set longitude. The longitude value will be canonicalized. Negative longitude is western hemisphere.

Parameters:
longitude - in degrees

compareTo

public int compareTo(GlobalCoordinates other)
Compare these coordinates to another set of coordiates. Western longitudes are less than eastern logitudes. If longitudes are equal, then southern latitudes are less than northern latitudes.

Specified by:
compareTo in interface java.lang.Comparable<GlobalCoordinates>
Parameters:
other - instance to compare to
Returns:
-1, 0, or +1 as per Comparable contract

hashCode

public int hashCode()
Get a hash code for these coordinates.

Overrides:
hashCode in class java.lang.Object
Returns:

equals

public boolean equals(java.lang.Object obj)
Compare these coordinates to another object for equality.

Overrides:
equals in class java.lang.Object
Parameters:
other -
Returns:

toString

public java.lang.String toString()
Get coordinates as a string.

Overrides:
toString in class java.lang.Object