|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.microedition.location.Coordinates
public class Coordinates
The Coordinates
class represents coordinates as
latitude-longitude-altitude values. The latitude and longitude values are
expressed in degrees using floating point values. The degrees are in decimal
values (rather than minutes/seconds). The coordinates are given using the
WGS84 datum.
This class also provides convenience methods for converting
between a String
coordinate representation and the double
representation used in this class.
Field Summary | |
---|---|
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 Summary | |
---|---|
Coordinates(double latitude,
double longitude,
float altitude)
Constructs a new Coordinates object with the values specified. |
Method Summary | |
---|---|
float |
azimuthTo(Coordinates to)
Calculates the azimuth between the two points according to the ellipsoid model of WGS84. |
static java.lang.String |
convert(double coordinate,
int outputType)
Converts a double representation of a coordinate with decimal
degrees into a String representation. |
static double |
convert(java.lang.String coordinate)
Converts a String representation of a coordinate into the
double representation as used in this API. |
float |
distance(Coordinates to)
Calculates the geodetic distance between the two points according to the ellipsoid model of WGS84. |
boolean |
equals(java.lang.Object obj)
Overriding the equals method in Object class to compare the
equality of values in two Coordinates objects. |
float |
getAltitude()
Returns the altitude component of this coordinate. |
double |
getLatitude()
Returns the latitude component of this coordinate. |
double |
getLongitude()
Returns the longitude component of this coordinate. |
int |
hashCode()
Overriding the hashCode method in Object class. |
void |
setAltitude(float altitude)
Sets the geodetic altitude for this point. |
void |
setLatitude(double latitude)
Sets the geodetic latitude for this point. |
void |
setLongitude(double longitude)
Sets the geodetic longitude for this point. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DD_MM_SS
Identifier for String
coordinate representation Degrees, Minutes,
Seconds and decimal fractions of a second.
public static final int DD_MM
Identifier for String
coordinate representation Degrees,
Minutes, decimal fractions of a minute.
Constructor Detail |
---|
public Coordinates(double latitude, double longitude, float altitude)
Constructs a new Coordinates
object with the values specified.
The latitude and longitude parameters are expressed in degrees using
floating point values. The degrees are in decimal values (rather than
minutes/seconds).
The coordinate values always apply to the WGS84 datum.
The Float.NaN
value can be used for altitude to indicate
that altitude is not known.
latitude
- The latitude of the location. Valid range:
[-90.0, 90.0]. Positive values indicate northern latitude
and negative values southern latitude.longitude
- The longitude of the location. Valid range:
[-180.0, 180.0]. Positive values indicate eastern longitude
and negative values western longitude.altitude
- The altitude of the location in meters, defined as height
above the WGS84 ellipsoid. Float.NaN
can be
used to indicate that altitude is not known.
java.lang.IllegalArgumentException
- if an input parameter is out of the
valid rangeMethod Detail |
---|
public double getLatitude()
Returns the latitude component of this coordinate. Positive values indicate northern latitude and negative values southern latitude.
The latitude is given in WGS84 datum.
setLatitude(double)
public double getLongitude()
Returns the longitude component of this coordinate. Positive values indicate eastern longitude and negative values western longitude.
The longitude is given in WGS84 datum.
setLongitude(double)
public float getAltitude()
Returns the altitude component of this coordinate. Altitude is defined
to mean height above the WGS84 reference ellipsoid. 0.0 means a location
at the ellipsoid surface, negative values mean the location is below
the ellipsoid surface, Float.NaN
that the altitude is not
available.
setAltitude(float)
public void setAltitude(float altitude)
Sets the geodetic altitude for this point.
altitude
- The altitude of the location in meters, defined as height
above the WGS84 ellipsoid. 0.0 means a location at the
ellipsoid surface, negative values mean the location is below
the ellipsoid surface, Float.NaN
that the
altitude is not availablegetAltitude()
public void setLatitude(double latitude)
Sets the geodetic latitude for this point. Latitude is given as a
double
expressing the latitude in degrees in the WGS84 datum.
latitude
- the latitude component of this location in degrees, valid
range: [-90.0, 90.0]
java.lang.IllegalArgumentException
- if latitude is out of the valid rangegetLatitude()
public void setLongitude(double longitude)
Sets the geodetic longitude for this point. Longitude is given as a
double
expressing the longitude in degrees in the WGS84 datum.
longitude
- the longitude of the location in degrees, valid range:
[-180.0, 180.0]
java.lang.IllegalArgumentException
- if longitude is out of the valid rangegetLongitude()
public static double convert(java.lang.String coordinate)
Converts a String
representation of a coordinate into the
double
representation as used in this API.
There are two string syntaxes supported:
1. Degrees, minutes, seconds and decimal fractions of seconds.
This is expressed as a String
complying with the following
EBNF definition where the degrees are within the range [-179, 179] and
the minutes and seconds are within the range [0, 59], or the degrees is
-180 or 180 and the minutes, seconds and decimal fractions are 0:
coordinate = degrees ":" minutes ":" seconds "." decimalfrac | degrees ":" minutes ":" seconds | degrees ":" minutes degrees = degreedigits | "-" degreedigits degreedigits = digit | nonzerodigit digit | "1" digit digit minutes = minsecfirstdigit digit seconds = minsecfirstdigit digit decimalfrac = 1*3digit digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" |"9" nonzerodigit = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" minsecfirstdigit = "0" | "1" | "2" | "3" | "4" | "5"
2. Degrees, minutes and decimal fractions of minutes.
This is expressed as a String
complying with the following
EBNF definition where the degrees are within the range [-179, 179] and the
minutes are within the range [0, 59], or the degrees is -180 or 180 and
the minutes and decimal fractions are 0:
coordinate = degrees ":" minutes "." decimalfrac | degrees ":" minutes degrees = degreedigits | "-" degreedigits degreedigits = digit | nonzerodigit digit | "1" digit digit minutes = minsecfirstdigit digit decimalfrac = 1*5digit digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" |"9" nonzerodigit = "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" minsecfirstdigit = "0" | "1" | "2" | "3" | "4" | "5"
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 above
double
value with decimal degrees that matches the
String
representation given as the parameter
java.lang.IllegalArgumentException
- if the coordinate
input parameter
does not comply with the defined syntax for the
specified types
java.lang.NullPointerException
- if coordinate
is null
public static java.lang.String convert(double coordinate, int outputType)
Converts a double
representation of a coordinate with decimal
degrees into a String
representation.
There are String
syntaxes supported are the same as for
the convert(String)
method. The implementation
shall provide as many significant digits for the decimal
fractions as are allowed by the String
syntax definition.
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.
String
representation of the coordinate in a
representation indicated by the parameter
java.lang.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)
Calculates the azimuth between the two points according to the ellipsoid
model of WGS84. The azimuth is relative to true north. 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. When the origin is the North pole and the destination is
not the North pole, this method returns 180.0. When the origin is the
South pole and the destination is not the South pole, this method returns
0.0. If the origin is equal to the destination, this method returns 0.0.
The implementation shall calculate the result as exactly
as it can. However, it is required that the result is within 1 degree of
the correct result.
to
- the Coordinates
of the destination
java.lang.NullPointerException
- if the parameter to
is null
public float distance(Coordinates to)
Calculates the geodetic distance between the two points according to the ellipsoid model of WGS84. Altitude is neglected from calculations.
The implementation shall calculate this as exactly
as it can. However, it is required that the result is within
0.36%
of the correct result.
to
- the Coordinates
of the destination
java.lang.NullPointerException
- if the parameter to
is null
public boolean equals(java.lang.Object obj)
Overriding the equals method in Object
class to compare the
equality of values in two Coordinates
objects. Since longitudes
values -180 and 180 denote the same longitude, they must
be considered equal.
equals
in class java.lang.Object
obj
- object to which the comparison is done
true
if all fields in the objects are equal,
else false
public int hashCode()
Overriding the hashCode
method in Object
class.
The method returns a hash code value for the coordinates object. Two
Coordinates
objects that are equal must have
the same hash code. For more information see
java.lang.Object.hashCode()
method.
hashCode
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |