public class Coordinates extends Object
Coordinates
class can hold coordinates for
latitude, longitude and altitude. The coordinates are defined with
the World Geodetic System 1984 (WGS84).
There are methods for converting between a string coordinate representation and the representation used in this class.
Modifier and Type | Field and Description |
---|---|
static int |
DD_MM
Identifier for string coordinate representation Degrees, Minutes,
decimal fractions of a minute
|
static int |
DD_MM_SS
Identifier for string coordinate representation Degrees, Minutes,
Seconds and decimal fractions of a second
|
Constructor and Description |
---|
Coordinates(double latitude,
double longitude,
float altitude)
Constructor for a new
Coordinates object. |
Modifier and Type | Method and Description |
---|---|
float |
azimuthTo(Coordinates to)
Calculates the azimuth between the two points according
to the ellipsoid model of WGS84.
|
static String |
convert(double coordinate,
int outputType)
Converts a double representation of a coordinate with decimal degrees
into a string representation.
|
static double |
convert(String coordinate)
Converts a String representation of a coordinate into the double
representation used by this class.
|
float |
distance(Coordinates to)
Calculates the geodetic distance between the two points according
to the ellipsoid model of WGS84.
|
float |
getAltitude()
Returns the altitude.
|
double |
getLatitude()
Returns the latitude (given in WGS84).
|
double |
getLongitude()
Returns the longitude (given in WGS84).
|
void |
setAltitude(float altitude)
Sets altitude.
|
void |
setLatitude(double latitude)
Sets the latitude.
|
void |
setLongitude(double longitude)
Sets the longitude.
|
public static final int DD_MM_SS
public static final int DD_MM
public Coordinates(double latitude, double longitude, float altitude)
Coordinates
object.
The coordinate values are given in the World Geodetic System 1984 (WGS84).
The altitude can be set to unknown with Float.NaN
latitude
- latitude, range is from -90.0 to 90.0.longitude
- longitude, range is from -180.0 to 180.0.altitude
- altitude in meters, defined as
height above the WGS84 ellipsoid. Can be set to unknown
with Float.NaN
IllegalArgumentException
- if an input parameter is out of
the valid rangepublic double getLatitude()
setLatitude(double)
public double getLongitude()
setLongitude(double)
public float getAltitude()
Float.NaN
indicates, that the altitude
is not available.setAltitude(float)
public void setAltitude(float altitude)
altitude
- the altitude of the location in meters, defined as
height above the WGS84 ellipsoid.
Float.NaN
indicates, that the altitude
is not available.getAltitude()
public void setLatitude(double latitude)
latitude
- the latitude component of this location in degrees.
Valid range:
[-90.0, 90.0].IllegalArgumentException
- if latitude is out of the
valid rangegetLatitude()
public void setLongitude(double longitude)
longitude
- the longitude of the location in degrees. Valid range:
[-180.0, 180.0)IllegalArgumentException
- if longitude is out of the
valid rangegetLongitude()
public static double convert(String coordinate)
There are two string syntaxes supported:
1. "Degrees:minutes:seconds.decimal fractions of seconds"
2. "Degrees:minutes.decimal fractions of minutes"
For example, for the double
value of the
coordinate 61.51d
, the corresponding syntax 1
string is "61:30:36"
and the corresponding syntax 2
string is "61:30.6"
.
coordinate
- a String in either of the two representation
specified aboveIllegalArgumentException
- if the coordinate input parameter
does not comply with the defined
syntax for the indicated typeNullPointerException
- if the coordinate string is
null
public static String convert(double coordinate, int outputType)
There are string syntaxes supported are the same as for
the convert(String)
method.
coordinate
- a double representation of a coordinateoutputType
- identifier of the type of the string representation
wanted for output
The constant DD_MM_SS
identifies the syntax 1 and
the constant DD_MM
identifies the syntax 2.IllegalArgumentException
- if the outputType is not one of the
two constant values defined in this
class or if the coordinate value
is not within the range
[-180.0, 180.0) or
is Double.NaN
convert(String)
public float azimuthTo(Coordinates to)
The Coordinates
object on which this method
is called is considered the origin for the calculation and
the Coordinates
object passed as a parameter
is the destination which the azimuth is calculated to.
to
- the Coordinates
of the destinationNullPointerException
- if the parameter
is null
public float distance(Coordinates to)
to
- the Coordinates
of the destinationNullPointerException
- if the parameter
is null
Copyright (c) 1990, 2012, Oracle and/or its affiliates. All rights reserved.