Package com.irurueta.navigation.utils
Class LocationUtils
java.lang.Object
com.irurueta.navigation.utils.LocationUtils
Location utility class based on Android's SDK Location class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Contains distance and bearing. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Constant used to specify formatting of a latitude or longitude in the form "[+-]DDD.DDDDD where D indicates degrees.static final int
Constant used to specify formatting of a latitude or longitude in the form "[+-]DDD:MM.MMMMM" where D indicates degrees and M indicates minutes of arc (1 minute = 1/60th of a degree).static final int
Constant used to specify formatting of a latitude or longitude in the form "DDD:MM:SS.SSSSS" where D indicates degrees, M indicates minutes of arc, and S indicates seconds of arc (1 minute = 1/60th of a degree, 1 second = 1/3600th of a degree). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
convert
(double coordinate, int outputType) Converts a coordinate to a String representation.static double
Converts a String in one of the formats described by FORMAT_DEGREES, FORMAT_MINUTES, or FORMAT_SECONDS into a double.distanceAndBearing
(double startLatitude, double startLongitude, double endLatitude, double endLongitude) Computes the approximate distance in meters between two locations, and the initial and final bearings of the shortest path between them.static void
distanceAndBearing
(double startLatitude, double startLongitude, double endLatitude, double endLongitude, double[] results) Computes the approximate distance in meters between two locations, and the initial and final bearings of the shortest path between them.static void
distanceAndBearing
(double startLatitude, double startLongitude, double endLatitude, double endLongitude, LocationUtils.BearingDistance results) Computes the approximate distance in meters between two locations, and the initial and final bearings of the shortest path between them.static com.irurueta.units.Distance
distanceBetween
(double startLatitude, double startLongitude, double endLatitude, double endLongitude) Computes the approximate distance between two locations.static com.irurueta.units.Distance
distanceBetween
(double startLatitude, double startLongitude, double endLatitude, double endLongitude, com.irurueta.units.Distance result) Computes the approximate distance between two locations.static double
distanceBetweenMeters
(double startLatitude, double startLongitude, double endLatitude, double endLongitude) Computes the approximate distance in meters between two locations.
-
Field Details
-
FORMAT_DEGREES
public static final int FORMAT_DEGREESConstant used to specify formatting of a latitude or longitude in the form "[+-]DDD.DDDDD where D indicates degrees.- See Also:
-
FORMAT_MINUTES
public static final int FORMAT_MINUTESConstant used to specify formatting of a latitude or longitude in the form "[+-]DDD:MM.MMMMM" where D indicates degrees and M indicates minutes of arc (1 minute = 1/60th of a degree).- See Also:
-
FORMAT_SECONDS
public static final int FORMAT_SECONDSConstant used to specify formatting of a latitude or longitude in the form "DDD:MM:SS.SSSSS" where D indicates degrees, M indicates minutes of arc, and S indicates seconds of arc (1 minute = 1/60th of a degree, 1 second = 1/3600th of a degree).- See Also:
-
-
Constructor Details
-
LocationUtils
private LocationUtils()Constructor. Prevents public instantiation.
-
-
Method Details
-
convert
Converts a coordinate to a String representation. The outputType may be one of FORMAT_DEGREES, FORMAT_MINUTES, or FORMAT_SECONDS. The coordinate must be a valid double between -180.0 and 180.0. This conversion is performed in a method that is dependent on the default locale, and so is not guaranteed to round-trip withconvert(String)
.- Parameters:
coordinate
- coordinate to be converted.outputType
- output format.- Returns:
- converted coordinate.
- Throws:
IllegalArgumentException
- if coordinate is less than -180.0, greater than 180.0, or is not a number.IllegalArgumentException
- if outputType is not one of FORMAT_DEGREES, FORMAT_MINUTES, or FORMAT_SECONDS.
-
convert
Converts a String in one of the formats described by FORMAT_DEGREES, FORMAT_MINUTES, or FORMAT_SECONDS into a double. This conversion is performed in a locale agnostic method, and so is not guaranteed to round-trip withconvert(double, int)
.- Parameters:
coordinate
- coordinate to be parsed.- Returns:
- parsed value.
- Throws:
NullPointerException
- if coordinate is nullIllegalArgumentException
- if the coordinate is not in one of the valid formats.
-
distanceAndBearing
public static LocationUtils.BearingDistance distanceAndBearing(double startLatitude, double startLongitude, double endLatitude, double endLongitude) Computes the approximate distance in meters between two locations, and the initial and final bearings of the shortest path between them. Distance and bearing are defined using the WGS84 ellipsoid.- Parameters:
startLatitude
- the starting latitude.startLongitude
- the starting longitude.endLatitude
- the ending latitude.endLongitude
- the ending longitude.- Returns:
- bearing and distance results.
-
distanceAndBearing
public static void distanceAndBearing(double startLatitude, double startLongitude, double endLatitude, double endLongitude, double[] results) Computes the approximate distance in meters between two locations, and the initial and final bearings of the shortest path between them. Distance and bearing are defined using the WGS84 ellipsoid.- Parameters:
startLatitude
- the starting latitude.startLongitude
- the starting longitude.endLatitude
- the ending latitude.endLongitude
- the ending longitude.results
- array containing results. First element will contain distance. Second element will contain initial bearing (optional). Third element will contain ending bearing (optional).- Throws:
IllegalArgumentException
- if results does not have at least 1 element.
-
distanceBetweenMeters
public static double distanceBetweenMeters(double startLatitude, double startLongitude, double endLatitude, double endLongitude) Computes the approximate distance in meters between two locations.- Parameters:
startLatitude
- the starting latitude.startLongitude
- the starting longitude.endLatitude
- the ending latitude.endLongitude
- the ending longitude.- Returns:
- distance in meters between two locations.
-
distanceBetween
public static com.irurueta.units.Distance distanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude) Computes the approximate distance between two locations.- Parameters:
startLatitude
- the starting latitude.startLongitude
- the starting longitude.endLatitude
- the ending latitude.endLongitude
- the ending longitude.- Returns:
- distance between two locations.
-
distanceBetween
public static com.irurueta.units.Distance distanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude, com.irurueta.units.Distance result) Computes the approximate distance between two locations.- Parameters:
startLatitude
- the starting latitude.startLongitude
- the starting longitude.endLatitude
- the ending latitude.endLongitude
- the ending longitude.result
- instance where distance between two locations is stored.- Returns:
- provided result instance.
-