javax.microedition.location
Class Coordinates

java.lang.Object
  extended by javax.microedition.location.Coordinates
Direct Known Subclasses:
QualifiedCoordinates

public class Coordinates
extends Object

This class has been designed to manage coordinates using JSR-179 Location API http://www.jcp.org/en/jsr/detail?id=179

Author:
Juan Antonio Brenha Moral (calculateDistanceAndAzimuth by Charles Manning)

Field Summary
static int DD_MM
          Identifier for string coordinate representation Degrees, Minutes, decimal fractions of a minute See Also:Constant Field Values
static int DD_MM_SS
          Identifier for string coordinate representation Degrees, Minutes, Seconds and decimal fractions of a second See Also:Constant Field Values
 
Constructor Summary
Coordinates(double latitude, double longitude)
           
Coordinates(double latitude, double longitude, double altitude)
          Create a Coordinate object with 3 parameters: latitude, longitude and altitude
 
Method Summary
 double azimuthTo(Coordinates to)
          Calculates the azimuth between the two points according to the ellipsoid model of WGS84.
static String convert(double coordinate, int outputType)
          UNTESTED as of April 7, 2009 - BB / /** 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 as used in this API.
 double distance(Coordinates to)
          Calculates the geodetic distance between the two points according to the ellipsoid model of WGS84.
 double getAltitude()
          Altitude above mean sea level.
 double getLatitude()
          Get latitude
 double getLongitude()
          Get Longitude
 void setAltitude(double altitude)
           
 void setLatitude(double latitude)
           
 void setLongitude(double longitude)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DD_MM

public static final int DD_MM
Identifier for string coordinate representation Degrees, Minutes, decimal fractions of a minute See Also:Constant Field Values

See Also:
Constant Field Values

DD_MM_SS

public static final int DD_MM_SS
Identifier for string coordinate representation Degrees, Minutes, Seconds and decimal fractions of a second See Also:Constant Field Values

See Also:
Constant Field Values
Constructor Detail

Coordinates

public Coordinates(double latitude,
                   double longitude,
                   double altitude)
Create a Coordinate object with 3 parameters: latitude, longitude and altitude

Parameters:
latitude -
longitude -
altitude -

Coordinates

public Coordinates(double latitude,
                   double longitude)
Method Detail

getLatitude

public double getLatitude()
Get latitude

Returns:
the latitude

setLatitude

public void setLatitude(double latitude)

setLongitude

public void setLongitude(double longitude)

getLongitude

public double getLongitude()
Get Longitude

Returns:
the longitude

setAltitude

public void setAltitude(double altitude)

getAltitude

public double getAltitude()
Altitude above mean sea level.

Returns:
the altitude

azimuthTo

public double 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.


convert

public static String convert(double coordinate,
                             int outputType)
                      throws IllegalArgumentException
UNTESTED as of April 7, 2009 - BB / /** 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.

Parameters:
coordinate - a double representation of a coordinate
outputType - 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.
Returns:
a string representation of the coordinate in a representation indicated by the parameter
Throws:
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
See Also:
convert(String)

convert

public static double convert(String coordinate)
                      throws IllegalArgumentException,
                             NullPointerException
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 BNF 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 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 BNF definition where the degrees are within the range [-179, 179] and the minutes are within the range [0, 59], or the degrees is -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".

Parameters:
coordinate - a String in either of the two representation specified above
Returns:
a double value with decimal degrees that matches the string representation given as the parameter
Throws:
IllegalArgumentException - if the coordinate input parameter does not comply with the defined syntax for the specified types
NullPointerException - if the coordinate string is null convert

distance

public double 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.

Parameters:
to - the point to calculate the geodetic to
Returns:
the distance