Last active
December 24, 2015 10:29
-
-
Save chuckha/6784946 to your computer and use it in GitHub Desktop.
lat/lon to dms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lat_sign(dec) | |
dec >= 0 ? 'N' : 'S' | |
end | |
def lon_sign(dec) | |
dec >= 0 ? 'E' : 'W' | |
end | |
def lat_to_dms(dec) | |
"#{dec_to_dms dec} #{lat_sign dec}" | |
end | |
def lon_to_dms(dec) | |
"#{dec_to_dms dec} #{lon_sign dec}" | |
end | |
def dec_to_dms(float_val) | |
d, r = float_val.abs.divmod 1 | |
m, r = (r*60).divmod 1 | |
s = r*60 | |
"#{ d }° #{ m }' %.4f" % s.round(4) | |
end | |
puts lat_to_dms 1.36812 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment