Package com.google.common.geometry
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
FieldsModifier and TypeFieldDescriptionstatic final S2LatLngThe center point the lat/lng coordinate system.private final doubleprivate final double -
Constructor Summary
ConstructorsModifierConstructorDescriptionS2LatLng()Default constructor for convenience when declaring arrays, etc.privateS2LatLng(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 TypeMethodDescriptionAdds the given point to this point.booleanReturns true if the given point is within1e-9radians of this point.booleanapproxEquals(S2LatLng o, double maxError) Returns true if both the latitude and longitude of the given point are withinmaxErrorradians of this point.booleanstatic S2LatLngfromDegrees(double latDegrees, double lngDegrees) Returns a new S2LatLng converted from degrees.static S2LatLngfromE5(int latE5, int lngE5) Returns a new S2LatLng converted from tens of microdegrees.static S2LatLngfromE6(int latE6, int lngE6) Returns a new S2LatLng converted from microdegrees.static S2LatLngfromE7(int latE7, int lngE7) Returns a new S2LatLng converted from tenths of a microdegree.static S2LatLngfromRadians(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.doublegetDistance(S2LatLng o, double radius) Returns the surface distance to the given point assuming a constant radius.inthashCode()booleanisValid()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.doubleReturns the latitude of this point as degrees.static S1AngledoubleReturns the latitude of this point as radians.lng()Returns the longitude of this point as a new S1Angle.doubleReturns the longitude of this point as degrees.doubleReturns the longitude of this point as radians.static S1Anglemul(double m) Scales this point by the given scaling factor.Returns a new S2LatLng based on this instance for whichisValid()will betrue.Subtracts the given point from this point.toPoint()Convert an S2LatLng to the equivalent unit-length vector (S2Point).toString()
-
Field Details
-
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
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
Convert a point (not necessarily normalized) to an S2LatLng.
-
-
Method Details
-
fromRadians
Returns a new S2LatLng specified in radians. -
fromDegrees
Returns a new S2LatLng converted from degrees. -
fromE5
Returns a new S2LatLng converted from tens of microdegrees. -
fromE6
Returns a new S2LatLng converted from microdegrees. -
fromE7
Returns a new S2LatLng converted from tenths of a microdegree. -
latitude
-
longitude
-
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
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
Returns a new S2LatLng based on this instance for whichisValid()will betrue.- 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.
- Latitude is clipped to the range
-
toPoint
Convert an S2LatLng to the equivalent unit-length vector (S2Point). -
getDistance
Return the distance (measured along the surface of the sphere) to the given point. -
getDistance
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
Scales this point by the given scaling factor. Note that there is no guarantee that the new point will be valid. -
equals
-
hashCode
public int hashCode() -
approxEquals
Returns true if both the latitude and longitude of the given point are withinmaxErrorradians of this point. -
approxEquals
Returns true if the given point is within1e-9radians of this point. This corresponds to a distance of less than1cmat the surface of the Earth. -
toString
-
toStringDegrees
-