Package org.gavaghan.geodesy
Class GlobalCoordinates
java.lang.Object
org.gavaghan.geodesy.GlobalCoordinates
- All Implemented Interfaces:
Serializable,Comparable<GlobalCoordinates>
- Direct Known Subclasses:
GlobalPosition
public class GlobalCoordinates
extends Object
implements Comparable<GlobalCoordinates>, 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:
-
Constructor Summary
ConstructorsConstructorDescriptionGlobalCoordinates(double latitude, double longitude) Construct a new GlobalCoordinates. -
Method Summary
Modifier and TypeMethodDescriptionintcompareTo(GlobalCoordinates other) Compare these coordinates to another set of coordiates.booleanCompare these coordinates to another object for equality.doubleGet latitude.doubleGet longitude.inthashCode()Get a hash code for these coordinates.voidsetLatitude(double latitude) Set latitude.voidsetLongitude(double longitude) Set longitude.toString()Get coordinates as a string.
-
Constructor Details
-
GlobalCoordinates
public GlobalCoordinates(double latitude, double longitude) Construct a new GlobalCoordinates. Angles will be canonicalized.- Parameters:
latitude- latitude in degreeslongitude- longitude in degrees
-
-
Method Details
-
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
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:
compareToin interfaceComparable<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. -
equals
Compare these coordinates to another object for equality. -
toString
Get coordinates as a string.
-