Module: GeoCalc::PrettyPrint

Defined in:
lib/geo_calc/pretty_print.rb

Instance Method Summary collapse

Instance Method Details

#to_lat(format = :dms, dp = 0) ⇒ Numeric|String

Returns the latitude of this point; signed numeric degrees if no format, otherwise format & dp

Parameters:

  • format: (String)

    Return value as ‘d’, ‘dm’, ‘dms’

  • dp: (Numeric)

    No of decimal places to display (0|2|4)

Returns:

  • (Numeric|String)

    : Numeric degrees if no format specified, otherwise deg/min/sec



13
14
15
16
# File 'lib/geo_calc/pretty_print.rb', line 13

def to_lat format = :dms, dp = 0
  return lat if !format
  GeoUnits::Converter.to_lat lat, format, dp
end

#to_lon(format, dp) ⇒ Number|String

Returns the longitude of this point; signed numeric degrees if no format, otherwise format & dp as per Geo.toLon()

Parameters:

  • [format]: (String)

    Return value as ‘d’, ‘dm’, ‘dms’

  • [dp=0|2|4]: (Number)

    No of decimal places to display

Returns:

  • (Number|String)

    Numeric degrees if no format specified, otherwise deg/min/sec



27
28
29
30
# File 'lib/geo_calc/pretty_print.rb', line 27

def to_lon format, dp
  return lon if !format
  GeoUnits::Converter.to_lon lon, format, dp
end

#to_s(format = :dms, dp = 0) ⇒ String

Returns Comma-separated latitude/longitude.

Returns:

  • (String)

    Comma-separated latitude/longitude



41
42
43
44
45
46
47
48
49
50
# File 'lib/geo_calc/pretty_print.rb', line 41

def to_s format = :dms, dp = 0 
  format ||= :dms

  return '-,-' if !lat || !lon

  _lat = GeoUnits::Converter.to_lat lat, format, dp
  _lon = GeoUnits::Converter.to_lon lon, format, dp

  "#{_lat}, #{_lon}"
end