Class S2LatLng


  • public class S2LatLng
    extends Object
    This class represents a point on the unit sphere as a pair of latitude-longitude coordinates. Like the rest of the "geometry" package, the intent is to represent spherical geometry as a mathematical abstraction, so functions that are specifically related to the Earth's geometry (e.g. easting/northing conversions) should be put elsewhere.
    • Field Detail

      • EARTH_RADIUS_METERS

        public static final double EARTH_RADIUS_METERS
        Approximate "effective" radius of the Earth in meters.
        See Also:
        Constant Field Values
      • CENTER

        public static final S2LatLng CENTER
        The center point the lat/lng coordinate system.
    • Constructor Detail

      • S2LatLng

        public S2LatLng​(S1Angle lat,
                        S1Angle lng)
        Basic constructor. The latitude and longitude must be within the ranges allowed by is_valid() below. TODO(dbeaumont): Make this a static factory method (fromLatLng() ?).
      • S2LatLng

        public S2LatLng()
        Default constructor for convenience when declaring arrays, etc. TODO(dbeaumont): Remove the default constructor (just use CENTER).
      • S2LatLng

        public S2LatLng​(S2Point p)
        Convert a point (not necessarily normalized) to an S2LatLng. TODO(dbeaumont): Make this a static factory method (fromPoint() ?).
    • Method Detail

      • fromRadians

        public static S2LatLng fromRadians​(double latRadians,
                                           double lngRadians)
      • fromDegrees

        public static S2LatLng fromDegrees​(double latDegrees,
                                           double lngDegrees)
      • fromE5

        public static S2LatLng fromE5​(long latE5,
                                      long lngE5)
      • fromE6

        public static S2LatLng fromE6​(long latE6,
                                      long lngE6)
      • fromE7

        public static S2LatLng fromE7​(long latE7,
                                      long lngE7)
      • lat

        public S1Angle lat()
        Returns the latitude of this point as a new S1Angle.
      • latRadians

        public double latRadians()
        Returns the latitude of this point as radians.
      • latDegrees

        public double latDegrees()
        Returns the latitude of this point as degrees.
      • lng

        public S1Angle lng()
        Returns the longitude of this point as a new S1Angle.
      • lngRadians

        public double lngRadians()
        Returns the longitude of this point as radians.
      • lngDegrees

        public double lngDegrees()
        Returns the longitude of this point as degrees.
      • isValid

        public boolean isValid()
        Return true if the latitude is between -90 and 90 degrees inclusive and the longitude is between -180 and 180 degrees inclusive.
      • normalized

        public S2LatLng normalized()
        Returns a new S2LatLng based on this instance for which isValid() will be true.
        • Latitude is clipped to the range [-90, 90]
        • Longitude is normalized to be in the range [-180, 180]

        If the current point is valid then the returned point will have the same coordinates.

      • toPoint

        public S2Point toPoint()
        Convert an S2LatLng to the equivalent unit-length vector (S2Point).
      • getDistance

        public S1Angle getDistance​(S2LatLng o)
        Return the distance (measured along the surface of the sphere) to the given point.
      • getDistance

        public double getDistance​(S2LatLng o,
                                  double radius)
        Returns the surface distance to the given point assuming a constant radius.
      • getEarthDistance

        public double getEarthDistance​(S2LatLng o)
        Returns the surface distance to the given point assuming the default Earth radius of EARTH_RADIUS_METERS.
      • add

        public S2LatLng add​(S2LatLng o)
        Adds the given point to this point. Note that there is no guarantee that the new point will be valid.
      • sub

        public S2LatLng sub​(S2LatLng o)
        Subtracts the given point from this point. Note that there is no guarantee that the new point will be valid.
      • mul

        public S2LatLng mul​(double m)
        Scales this point by the given scaling factor. Note that there is no guarantee that the new point will be valid.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • approxEquals

        public boolean approxEquals​(S2LatLng o,
                                    double maxError)
        Returns true if both the latitude and longitude of the given point are within maxError radians of this point.
      • approxEquals

        public boolean approxEquals​(S2LatLng o)
        Returns true if the given point is within 1e-9 radians of this point. This corresponds to a distance of less than 1cm at the surface of the Earth.
      • toStringDegrees

        public String toStringDegrees()