Class S2LatLng

java.lang.Object
com.google.common.geometry.S2LatLng
All Implemented Interfaces:
Serializable

@Immutable @GwtCompatible(serializable=true, emulated=true) public final class S2LatLng extends Object implements Serializable
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. Note that the serialized form of this class is not stable and should not be relied upon for long-term persistence.
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final S2LatLng
    The center point the lat/lng coordinate system.
    private final double
     
    private final double
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    Default constructor for convenience when declaring arrays, etc.
    private
    S2LatLng(double latRadians, double lngRadians)
    This is internal to avoid ambiguity about which units are expected.
     
    Basic constructor.
     
    Convert a point (not necessarily normalized) to an S2LatLng.
  • Method Summary

    Modifier and Type
    Method
    Description
    Adds the given point to this point.
    boolean
    Returns true if the given point is within 1e-9 radians of this point.
    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.
    boolean
    equals(Object that)
     
    static S2LatLng
    fromDegrees(double latDegrees, double lngDegrees)
    Returns a new S2LatLng converted from degrees.
    static S2LatLng
    fromE5(int latE5, int lngE5)
    Returns a new S2LatLng converted from tens of microdegrees.
    static S2LatLng
    fromE6(int latE6, int lngE6)
    Returns a new S2LatLng converted from microdegrees.
    static S2LatLng
    fromE7(int latE7, int lngE7)
    Returns a new S2LatLng converted from tenths of a microdegree.
    static S2LatLng
    fromRadians(double latRadians, double lngRadians)
    Returns a new S2LatLng specified in radians.
    Return the distance (measured along the surface of the sphere) to the given point.
    double
    getDistance(S2LatLng o, double radius)
    Returns the surface distance to the given point assuming a constant radius.
    int
     
    boolean
    Return true if the latitude is between -90 and 90 degrees inclusive and the longitude is between -180 and 180 degrees inclusive.
    lat()
    Returns the latitude of this point as a new S1Angle.
    double
    Returns the latitude of this point as degrees.
    static S1Angle
     
    double
    Returns the latitude of this point as radians.
    lng()
    Returns the longitude of this point as a new S1Angle.
    double
    Returns the longitude of this point as degrees.
    double
    Returns the longitude of this point as radians.
    static S1Angle
     
    mul(double m)
    Scales this point by the given scaling factor.
    Returns a new S2LatLng based on this instance for which isValid() will be true.
    Subtracts the given point from this point.
    Convert an S2LatLng to the equivalent unit-length vector (S2Point).
     
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • CENTER

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

      private final double latRadians
    • lngRadians

      private final double lngRadians
  • Constructor Details

    • S2LatLng

      private S2LatLng(double latRadians, double lngRadians)
      This is internal to avoid ambiguity about which units are expected.
    • S2LatLng

      public S2LatLng(S1Angle lat, S1Angle lng)
      Basic constructor. The latitude and longitude must be within the ranges allowed by is_valid() below.
    • S2LatLng

      public S2LatLng()
      Default constructor for convenience when declaring arrays, etc.
    • S2LatLng

      public S2LatLng(S2Point p)
      Convert a point (not necessarily normalized) to an S2LatLng.
  • Method Details

    • fromRadians

      public static S2LatLng fromRadians(double latRadians, double lngRadians)
      Returns a new S2LatLng specified in radians.
    • fromDegrees

      public static S2LatLng fromDegrees(double latDegrees, double lngDegrees)
      Returns a new S2LatLng converted from degrees.
    • fromE5

      public static S2LatLng fromE5(int latE5, int lngE5)
      Returns a new S2LatLng converted from tens of microdegrees.
    • fromE6

      public static S2LatLng fromE6(int latE6, int lngE6)
      Returns a new S2LatLng converted from microdegrees.
    • fromE7

      public static S2LatLng fromE7(int latE7, int lngE7)
      Returns a new S2LatLng converted from tenths of a microdegree.
    • latitude

      public static S1Angle latitude(S2Point p)
    • longitude

      public static S1Angle longitude(S2Point p)
    • 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

      @CheckReturnValue 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.
    • add

      Adds the given point to this point. Note that there is no guarantee that the new point will be valid.
    • sub

      Subtracts the given point from this point. Note that there is no guarantee that the new point will be valid.
    • mul

      @CheckReturnValue 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.
    • equals

      public boolean equals(Object that)
      Overrides:
      equals in class Object
    • 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.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toStringDegrees

      public String toStringDegrees()