class Gmaps::CoordinateParser

Overview

Parses geographic coordinates in various formats and returns a LatLon value.

Supports formats like:

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.cr

Constant 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

Instance Method Summary

Class Method Detail

def self.parse(coordinates : String) : LatLon #

[View source]
def self.parse_lat_lng(latitude : String | Nil, longitude : String | Nil) #

[View source]

Instance Method Detail

def coord_from_matcher(m : Regex::MatchData, idx1 : Int32, idx2 : Int32, idx3 : Int32, sign : String | Char) : Float64 #

[View source]
def coord_from_matcher(m : Regex::MatchData, idx1 : Int32, idx2 : Int32, sign : String | Char) : Float64 #

[View source]
def coord_from_matcher(m : Regex::MatchData, idx1 : Int32, sign : String | Char) : Float64 #

[View source]
def coord_sign(direction) #

[View source]
def count_matches(s : String, c : Char) : Int32 #

[View source]
def dms_to_decimal(degree : Float64, minutes : Float64 | Nil = nil, seconds : Float64 | Nil = nil) : Float64 #

[View source]
def in_range(lat, lon) #

[View source]
def is_lat?(direction) #

[View source]
def order_coordinates(dir1 : String, dir2 : String, c1 : Float64, c2 : Float64) : LatLon #

[View source]
def parse(coordinates : String) : LatLon #

[View source]
def parse_dms(coord : String, is_lat_coord : Bool) : Float64 #

[View source]
def parse_lat_lng(latitude : String, longitude : String) : LatLon #

[View source]
def round_to_8_decimals(x : Float64 | Nil) : Float64 | Nil #

[View source]
def validate_and_round(lat : Float64, lon : Float64) : LatLon #

[View source]