public class SimpleGeospatialPoint extends Object implements GeospatialPoint
A simple geospatial point implementation. Simple geospatial points calculate distance to other points using the Haversine Formula.
EARTH_RADIUS
Constructor and Description |
---|
SimpleGeospatialPoint(double latitude,
double longitude)
Constructs a new geospatial point at the given latitude and longitude
coordinates.
|
SimpleGeospatialPoint(GeospatialPoint p)
Constructs a new geospatial point at the same coordinates as the given
point.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj)
Compares this point to another object.
|
double |
getDistanceTo(double latitude,
double longitude)
Returns the "great circle" distance to another geospatial point.
|
double |
getDistanceTo(GeospatialPoint otherPoint)
Returns the "great circle" distance to another geospatial point.
|
double |
getLatitude()
Returns the latitude of this point.
|
double |
getLongitude()
Returns the longitude of this point.
|
int |
hashCode()
Generates a hash code value for this point.
|
void |
setLatitude(double latitude)
Sets the latitude of this point.
|
void |
setLongitude(double longitude)
Sets the longitude of this point.
|
String |
toString()
Returns a human-readable
String representation of this point. |
public SimpleGeospatialPoint(double latitude, double longitude)
latitude
- the latitude of this point in degreeslongitude
- the longitude of this point in degreesIllegalArgumentException
- if the given latitude is outside of the allowable rangepublic SimpleGeospatialPoint(GeospatialPoint p)
p
- the point whose location should be used for this pointpublic void setLatitude(double latitude)
latitude
- the latitude of this point in degreesIllegalArgumentException
- if the given latitude is outside of the allowable rangepublic double getLatitude()
getLatitude
in interface GeospatialPoint
public void setLongitude(double longitude)
longitude
- the longitude of this point in degreespublic double getLongitude()
getLongitude
in interface GeospatialPoint
public double getDistanceTo(GeospatialPoint otherPoint)
getDistanceTo
in interface GeospatialPoint
otherPoint
- the other point to which to calculate distanceGeospatialPoint.EARTH_RADIUS
public double getDistanceTo(double latitude, double longitude)
getDistanceTo
in interface GeospatialPoint
latitude
- the latitude, in degrees, of the other point to which to
calculate distancelongitude
- the longitude, in degrees, of the other point to which to
calculate distanceGeospatialPoint.EARTH_RADIUS
public String toString()
String
representation of this point.public int hashCode()
public boolean equals(Object obj)
null
, is also a SimpleGeospatialPoint
(or a subclass thereof), and has the same latitude and longitude as this
point.jeospatial is an open-source library hosted at https://github.com/jchambers/jeospatial.