Geo::Coord
Inherits Comparable / Struct / Value / Object
A Coord is a point in geographical coordinates: latitude and longitude.
Constants
Constructors
Instance methods
The comparison operator. Returns 0 if the two objects are equal,
a negative number if this object is considered less than other,
a positive number if this object is considered greater than other,
or nil if the two objects are not comparable.
Subclasses define this method to provide class-specific ordering.
The comparison operator is usually used to sort values:
# Sort in a descending way:
[3, 1, 2].sort { |x, y| y <=> x } # => [3, 2, 1]
# Sort in an ascending way:
[3, 1, 2].sort { |x, y| x <=> y } # => [1, 2, 3]
Calculates initial and final bearings between two points using great-circle distance formulas
Calculates the location of a destination point
Calculates distance to other.
Haversine formula is used.
Formats coordinates according to directives in formatstr.
Each directive starts with % and can contain some modifiers before its name.
Acceptable modifiers:
- unsigned integers: none;
- signed integers:
+for mandatory sign printing; - floats: same as integers and number of digits modifier, like
0.3.
List of directives:
%lat- Full latitude, floating point, signed%latds- Latitude degrees, integer, signed%latd- Latitude degrees, integer, unsigned%latm- Latitude minutes, integer, unsigned%lats- Latitude seconds, floating point, unsigned%lath- Latitude hemisphere, "N" or "S"%lng- Full longitude, floating point, signed%lngds- Longitude degrees, integer, signed%lngd- Longitude degrees, integer, unsigned%lngm- Longitude minutes, integer, unsignedlngs- Longitude seconds, floating point, unsigned- `%lngh`` - Longitude hemisphere, "E" or "W"
Examples:
g = Geo::Coord.new(50.004444, 36.231389)
g.strfcoord('%+lat, %+lng')
# => "+50.004444, +36.231389"
g.strfcoord("%latd°%latm'%lath -- %lngd°%lngm'%lngh")
# => "50°0'N -- 36°13'E"
strfcoord handles seconds rounding implicitly:
pos = Geo::Coord.new(0.033333, 91.333333)
pos.strfcoord('%latd %latm %0.5lats') # => "0 1 59.99880"
pos.strfcoord('%latd %latm %lats') # => "0 2 0"
Returns a string representing coordinates.
g.to_s # => "50°0'16\"N 36°13'53\"E"
g.to_s(dms: false) # => "50.004444,36.231389"