Class Coordinates
- java.lang.Object
-
- lejos.hardware.gps.Coordinates
-
public class Coordinates extends java.lang.ObjectThis 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
Fields Modifier and Type Field Description static intDD_MMIdentifier for string coordinate representation Degrees, Minutes, decimal fractions of a minute See Also:Constant Field Valuesstatic intDD_MM_SSIdentifier for string coordinate representation Degrees, Minutes, Seconds and decimal fractions of a second See Also:Constant Field Values
-
Constructor Summary
Constructors Constructor Description 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doubleazimuthTo(Coordinates to)Calculates the azimuth between the two points according to the ellipsoid model of WGS84.static java.lang.Stringconvert(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 doubleconvert(java.lang.String coordinate)Converts a String representation of a coordinate into the double representation as used in this API.doubledistance(Coordinates to)Calculates the geodetic distance between the two points according to the ellipsoid model of WGS84.doublegetAltitude()Altitude above mean sea level.doublegetLatitude()Returns the latitude component of this coordinate.doublegetLongitude()Returns the longitude component of this coordinate.voidsetAltitude(double altitude)voidsetLatitude(double latitude)voidsetLongitude(double longitude)
-
-
-
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
-
-
Method Detail
-
getLatitude
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.
- Returns:
- the latitude in degrees
- See Also:
setLatitude(double)
-
setLatitude
public void setLatitude(double latitude)
-
setLongitude
public void setLongitude(double longitude)
-
getLongitude
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.
- Returns:
- the longitude in degrees
- See Also:
setLongitude(double)
-
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.
The azimuth (in degrees) increases clockwise. On this coordinate system, north is 0 degrees, east is 90 degrees, south is 180 degrees, and west is 270 degrees.
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 java.lang.String convert(double coordinate, int outputType) throws java.lang.IllegalArgumentExceptionUNTESTED 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 coordinateoutputType- identifier of the type of the string representation wanted for output The constantDD_MM_SSidentifies the syntax 1 and the constantDD_MMidentifies the syntax 2.- Returns:
- a string representation of the coordinate in a representation indicated by the parameter
- Throws:
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- See Also:
convert(String)
-
convert
public static double convert(java.lang.String coordinate) throws java.lang.IllegalArgumentException, java.lang.NullPointerExceptionConverts 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:
java.lang.IllegalArgumentException- if the coordinate input parameter does not comply with the defined syntax for the specified typesjava.lang.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 in meters
-
-