de.monarchy.guideme.util
Class GeoCoordinate

java.lang.Object
  extended by de.monarchy.guideme.util.GeoCoordinate
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
PointOfInterest

public class GeoCoordinate
extends java.lang.Object
implements java.io.Serializable

GeoCoordinate represents a location on a globe, represented by latitude and longitude. Latitude is measured in degrees from -90 to 90, with 0 being at the equator and positive values representing positions on the northern hemisphere, negative values positions on the southern. Longitude is measured in degrees from -180 to 180 with 0 being the prime meridian and negative values being west of it, positive in the east.

Author:
dstuerze
See Also:
Serialized Form

Field Summary
static double DEG_TO_RAD
          conversion of degrees to radian
static double EARTH_RADIUS
          earth radius in meters
static double RAD_TO_DEG
          conversion of radian to degrees
 
Constructor Summary
GeoCoordinate(double lat, double lon)
          Creates a geo coordinate representing the position at lat, lon
GeoCoordinate(GeoCoordinate copy)
          Copies the values of the given coordinate to the new one.
 
Method Summary
 double distanceTo(GeoCoordinate another)
          Returns the distance between to points on the unit sphere.
 boolean equals(java.lang.Object o)
           
 double getLatitude()
          Returns the latitude.
 double getLongitude()
          Returns the longitude.
 int hashCode()
           
 void setLatitude(double latitude)
          Sets the latitude.
 void setLongitude(double longitude)
          Sets the longitude.
 java.lang.String toString()
           
 double trackAngle(GeoCoordinate another)
          Returns the angle a given point lies in relation to this.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

EARTH_RADIUS

public static final double EARTH_RADIUS
earth radius in meters

See Also:
Constant Field Values

DEG_TO_RAD

public static final double DEG_TO_RAD
conversion of degrees to radian

See Also:
Constant Field Values

RAD_TO_DEG

public static final double RAD_TO_DEG
conversion of radian to degrees

See Also:
Constant Field Values
Constructor Detail

GeoCoordinate

public GeoCoordinate(double lat,
                     double lon)
Creates a geo coordinate representing the position at lat, lon

Parameters:
lat - latitude
lon - longitude

GeoCoordinate

public GeoCoordinate(GeoCoordinate copy)
Copies the values of the given coordinate to the new one.

Parameters:
copy - coordinate to be copied
Method Detail

getLongitude

public double getLongitude()
Returns the longitude.

Returns:
longitude

setLongitude

public void setLongitude(double longitude)
Sets the longitude. Value has to be between -180 and 180.

Parameters:
longitude - new longitude
Throws:
java.lang.IllegalArgumentException - if values unfitting

getLatitude

public double getLatitude()
Returns the latitude.

Returns:
latitude

setLatitude

public void setLatitude(double latitude)
Sets the latitude. Value has to be between -90 and 90.

Parameters:
latitude - new latitude
Throws:
java.lang.IllegalArgumentException - if values unfitting

distanceTo

public double distanceTo(GeoCoordinate another)
Returns the distance between to points on the unit sphere. The sphere in this case has a radius of 1 metre, so the result has to be scaled if necessary. The distance calculated is the great-circle distance between two points, which means it represents the shortest possible path. As for performance reasons, the distance is not calculated in wgs 84, but on a sphere.

Parameters:
another - other point the distance is calculated to
Returns:
distance on unit sphere

trackAngle

public double trackAngle(GeoCoordinate another)
Returns the angle a given point lies in relation to this. The track angle is zero at north, increasing clockwise in radian. This method uses rhumb lines to calculate the direction, so the angle will remain the same while the objects would approach each other. Movement along a rhumb line is not the shortest way. At distances of up to 30 degrees in longitude the bias is less than one percent. The rhumb line is calculated on a unit sphere for performance reasons.

Parameters:
another - other point whose direction is needed
Returns:
angle in radian

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object