Package huskymaps

Class Location


  • public class Location
    extends Object
    A physical place in the world represented as longitude, latitude, and (optionally) a name.
    See Also:
    Location.Builder, MapGraph
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Location.Builder
      Interactively constructs a new location when the fields are not all immediately available.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int DECIMAL_PLACES  
      private static double EPSILON
      Error tolerance for latitudes and longitudes.
      double lat
      The latitude of this location.
      double lon
      The longitude of this location.
      String name
      The name of this location (or null).
      private static int R
      Radius of the Earth in miles.
    • Constructor Summary

      Constructors 
      Constructor Description
      Location​(double lon, double lat, String name)
      Constructs a new location from the given longitude, latitude, and name.
    • Field Detail

      • EPSILON

        private static final double EPSILON
        Error tolerance for latitudes and longitudes.
        See Also:
        Constant Field Values
      • lon

        public final double lon
        The longitude of this location.
      • lat

        public final double lat
        The latitude of this location.
      • name

        public final String name
        The name of this location (or null).
    • Constructor Detail

      • Location

        public Location​(double lon,
                        double lat,
                        String name)
        Constructs a new location from the given longitude, latitude, and name.
        Parameters:
        lon - the longitude.
        lat - the latitude.
        name - the name.
    • Method Detail

      • parse

        public static Location parse​(String... lonLat)
        Returns a new location from parsing the first two elements of the given array of strings.
        Parameters:
        lonLat - an array of strings where the first two elements represent the longitude and latitude.
        Returns:
        a new location from parsing the string longitude and string latitude.
      • distance

        public double distance​(Location other)
        Returns the great-circle (haversine) distance between geographic coordinates.
        Parameters:
        other - The other location.
        Returns:
        The great-circle distance between the two vertices.
        See Also:
        https://www.movable-type.co.uk/scripts/latlong.html
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object