Class LocationUtils

java.lang.Object
com.irurueta.navigation.utils.LocationUtils

public class LocationUtils extends Object
Location utility class based on Android's SDK Location class.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Contains distance and bearing.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static 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
    Modifier
    Constructor
    Description
    private
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    convert(double coordinate, int outputType)
    Converts a coordinate to a String representation.
    static double
    convert(String coordinate)
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FORMAT_DEGREES

      public static final int FORMAT_DEGREES
      Constant 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_MINUTES
      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).
      See Also:
    • FORMAT_SECONDS

      public static final int FORMAT_SECONDS
      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).
      See Also:
  • Constructor Details

    • LocationUtils

      private LocationUtils()
      Constructor. Prevents public instantiation.
  • Method Details

    • convert

      public static String convert(double coordinate, int outputType)
      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 with convert(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

      public static double convert(String coordinate)
      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 with convert(double, int).
      Parameters:
      coordinate - coordinate to be parsed.
      Returns:
      parsed value.
      Throws:
      NullPointerException - if coordinate is null
      IllegalArgumentException - if the coordinate is not in one of the valid formats.
    • distanceAndBearing

      public 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. 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 - instance containing results.
    • 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.