ps2
Class GeoPoint

java.lang.Object
  extended by ps2.GeoPoint

public class GeoPoint
extends Object

A GeoPoint models a point on the earth. GeoPoints are immutable.

North latitudes and east longitudes are represented by positive numbers. South latitudes and west longitudes are represented by negative numbers. In each case, the precision is to a millionth of a degree.

The code may assume that the represented points are nearby Seattle.

Implementation hint:
Seattle is at approximately 47 deg. 36 min. 35 sec. N latitude and 122 deg. 19 min. 59 sec. W longitude. There are 60 minutes per degree, and 60 seconds per minute. So, in decimal, these correspond to 47.609722 North latitude and -122.333056 East longitude. The constructor takes integers in millionths of degrees. To create a new GeoPoint located in Seattle, use: GeoPoint seattle = new GeoPoint(47609722, -122333056);

Near Seattle, there are approximately 69.04 miles per degree of latitude and 47.574 miles per degree of longitude. An implementation should use these values when determining distances and headings.

Specification Fields

Field Summary
Modifier and Type Field and Description
static int MAX_LATITUDE
          Maximum value the latitude field can have in this class.
static int MAX_LONGITUDE
          Maximum value the longitude field can have in this class.
static double MILES_PER_DEGREE_LATITUDE
          Approximation used to determine distances and headings using a "flat earth" simplification.
static double MILES_PER_DEGREE_LONGITUDE
          Approximation used to determine distances and headings using a "flat earth" simplification.
static int MIN_LATITUDE
          Minimum value the latitude field can have in this class.
static int MIN_LONGITUDE
          Minimum value the longitude field can have in this class.
 
Constructor Summary
Constructor and Description
GeoPoint(int latitude, int longitude)
           
 
Method Summary
Modifier and Type Method and Description
 double distanceTo(GeoPoint gp)
          Computes the distance between GeoPoints.
 boolean equals(Object gp)
          Compares the specified Object with this GeoPoint for equality.
 int getLatitude()
          the latitude of the GeoPoint object, in millionths of degrees.
 int getLongitude()
          the longitude of the GeoPoint object, in millionths of degrees.
 int hashCode()
           
 double headingTo(GeoPoint gp)
          Computes the compass heading between GeoPoints.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_LATITUDE

public static final int MIN_LATITUDE
Minimum value the latitude field can have in this class.

See Also:
Constant Field Values

MAX_LATITUDE

public static final int MAX_LATITUDE
Maximum value the latitude field can have in this class.

See Also:
Constant Field Values

MIN_LONGITUDE

public static final int MIN_LONGITUDE
Minimum value the longitude field can have in this class.

See Also:
Constant Field Values

MAX_LONGITUDE

public static final int MAX_LONGITUDE
Maximum value the longitude field can have in this class.

See Also:
Constant Field Values

MILES_PER_DEGREE_LATITUDE

public static final double MILES_PER_DEGREE_LATITUDE
Approximation used to determine distances and headings using a "flat earth" simplification.

See Also:
Constant Field Values

MILES_PER_DEGREE_LONGITUDE

public static final double MILES_PER_DEGREE_LONGITUDE
Approximation used to determine distances and headings using a "flat earth" simplification.

See Also:
Constant Field Values
Constructor Detail

GeoPoint

public GeoPoint(int latitude,
                int longitude)
Requires:
the (latitude, longitude) point expressed in millionths of a degree is valid, such that MIN_LATITUDE <= latitude <= MAX_LATITUDE and MIN_LONGITUDE <= longitude <= MAX_LONGITUDE
Effects:
constructs a GeoPoint from a latitude and longitude given in millionths of degrees.
Method Detail

getLatitude

public int getLatitude()
the latitude of the GeoPoint object, in millionths of degrees.


getLongitude

public int getLongitude()
the longitude of the GeoPoint object, in millionths of degrees.


distanceTo

public double distanceTo(GeoPoint gp)
Computes the distance between GeoPoints.

Returns:
The distance, in miles, from this to gp, using the flat-surface, near Seattle approximation.
Requires:
gp != null

headingTo

public double headingTo(GeoPoint gp)
Computes the compass heading between GeoPoints.

Returns:
The compass heading h from this to gp, in degrees, using the flat-surface, near Seattle approximation, such that 0 ≤ h < 360. In compass headings, north = 0, east = 90, south = 180, and west = 270.
Requires:
gp != null && !this.equals(gp)

equals

public boolean equals(Object gp)
Compares the specified Object with this GeoPoint for equality.

Overrides:
equals in class Object
Returns:
gp != null && (gp instanceof GeoPoint) && gp.latitude = this.latitude && gp.longitude = this.longitude

hashCode

public int hashCode()
Overrides:
hashCode in class Object
Returns:
a valid hashcode for this GeoPoint.

toString

public String toString()
Overrides:
toString in class Object
Returns:
a string representation of this GeoPoint.