Struct LatLon
A WGS84 geographic coordinate in degrees, validated at construction.
public readonly struct LatLon : IEquatable<LatLon>
- Implements
Remarks
Latitude is positive north, longitude positive east. The constructor throws rather than clamping, so an out-of-range value fails where it is produced instead of silently landing somewhere plausible. Use ClampToMercator(double, double) when clamping is what you want.
Constructors
LatLon(double, double)
Creates a coordinate, rejecting out-of-range values.
public LatLon(double lat, double lon)
Parameters
latdoubleLatitude in degrees WGS84, -90 to 90.
londoubleLongitude in degrees WGS84, -180 to 180.
Exceptions
- ArgumentOutOfRangeException
Either value is NaN or outside its range.
Fields
MercatorMaxLat
The highest latitude Web Mercator can represent, 85.05112878 degrees. The projection sends the poles to infinity, so the square map is cut at this parallel.
public const double MercatorMaxLat = 85.05112878
Field Value
Properties
Lat
Latitude in degrees WGS84, -90 to 90, positive north.
public double Lat { get; }
Property Value
Lon
Longitude in degrees WGS84, -180 to 180, positive east.
public double Lon { get; }
Property Value
Methods
ClampToMercator(double, double)
Creates a coordinate with latitude clamped into the Web Mercator range, for input that may reach the poles.
public static LatLon ClampToMercator(double lat, double lon)
Parameters
latdoubleLatitude in degrees WGS84; clamped to +/- MercatorMaxLat.
londoubleLongitude in degrees WGS84, -180 to 180. Not clamped.
Returns
- LatLon
A coordinate the projection can represent.
Equals(LatLon)
Exact component-wise equality. No distance tolerance.
public bool Equals(LatLon other)
Parameters
otherLatLon
Returns
Equals(object)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
ToString()
Returns "(lat,lon)".
public override string ToString()