class Gmaps::CoordinateParser
- Gmaps::CoordinateParser
- Reference
- Object
Overview
Parses geographic coordinates in various formats and returns a LatLon value.
Supports formats like:
- Degrees Minutes Seconds (DMS): 41°24'12.2"N 2°10'26.5"E
- Degrees Minutes (DM): 41°24.2'N 2°10.4'E
- Decimal Degrees (DD): 41.40333 2.17403
Latitude ranges from -90 to 90. Longitude ranges from -180 to 180.
Can raise a ParseException on invalid input. Some Examples of usage: CoordinateParser.parse("41°24'12.2"N 2°10'26.5"E") CoordinateParser.parse("41.40333 2.17403") CoordinateParser.parse("41°24.2'N 2°10.4'E") CoordinateParser.parse("41.40333 2.17403")
Defined in:
gmaps/coordinate_parser.crConstant Summary
-
D =
"\\s*(\\d{1,3}(?:[,.]\\d+)?)\\s*(?:°|d|º| |g|o|)\\s*"
-
D_SINGLE =
/#{D}$/i
-
DM =
((("\\s*(\\d{1,3})\\s*(?:°|d|º| |g|o)" + "\\s*(?:") + "([0-6]?\\d(?:[,.]\\d+)?)") + "\\s*(?:'|m| |´|’|′)?") + ")?\\s*"
-
DM_COORD =
/#{DM}#{NSEOW}#{SEPARATORS}#{DM}([NSEOW])$/i
-
DM_COORD_2 =
/#{NSEOW}#{DM}#{SEPARATORS}#{NSEOW}#{DM}$/i
-
DM_SINGLE =
/#{DM}$/i
-
DMS =
(((("\\s*(\\d{1,3})\\s*(?:°|d|º| |g|o)" + "\\s*([0-6]?\\d)\\s*(?:'|m| |´|’|′)") + "\\s*(?:") + "([0-6]?\\d(?:[,.]\\d+)?)") + "\\s*(?:\"|''|s|´´|″)?") + ")?\\s*"
-
DMS_COORD =
/#{DMS}#{NSEOW}#{SEPARATORS}#{DMS}([NSEOW])$/i
-
DMS_COORD_2 =
/#{NSEOW}#{DMS}#{SEPARATORS}#{NSEOW}#{DMS}$/i
-
DMS_SINGLE =
/#{DMS}$/i
-
Log =
::Log.for("coord_parser")
-
NSEOW =
"([NSEOW])"
-
POSITIVE =
"NEO"
-
SEPARATORS =
"[ ,;/]?"
Class Method Summary
- .parse(coordinates : String) : LatLon
- .parse_lat_lng(latitude : String | Nil, longitude : String | Nil)
Instance Method Summary
- #coord_from_matcher(m : Regex::MatchData, idx1 : Int32, idx2 : Int32, idx3 : Int32, sign : String | Char) : Float64
- #coord_from_matcher(m : Regex::MatchData, idx1 : Int32, idx2 : Int32, sign : String | Char) : Float64
- #coord_from_matcher(m : Regex::MatchData, idx1 : Int32, sign : String | Char) : Float64
- #coord_sign(direction)
- #count_matches(s : String, c : Char) : Int32
- #dms_to_decimal(degree : Float64, minutes : Float64 | Nil = nil, seconds : Float64 | Nil = nil) : Float64
- #in_range(lat, lon)
- #is_lat?(direction)
- #order_coordinates(dir1 : String, dir2 : String, c1 : Float64, c2 : Float64) : LatLon
- #parse(coordinates : String) : LatLon
- #parse_dms(coord : String, is_lat_coord : Bool) : Float64
- #parse_lat_lng(latitude : String, longitude : String) : LatLon
- #round_to_8_decimals(x : Float64 | Nil) : Float64 | Nil
- #validate_and_round(lat : Float64, lon : Float64) : LatLon
Class Method Detail
Instance Method Detail
def coord_from_matcher(m : Regex::MatchData, idx1 : Int32, idx2 : Int32, idx3 : Int32, sign : String | Char) : Float64
#
def coord_from_matcher(m : Regex::MatchData, idx1 : Int32, idx2 : Int32, sign : String | Char) : Float64
#
def coord_from_matcher(m : Regex::MatchData, idx1 : Int32, sign : String | Char) : Float64
#
def dms_to_decimal(degree : Float64, minutes : Float64 | Nil = nil, seconds : Float64 | Nil = nil) : Float64
#