Created
August 11, 2010 20:52
-
-
Save laurynas/519740 to your computer and use it in GitHub Desktop.
Convert decimal to degrees, minutes, seconds sexagesimal (used for GPS coordinates)
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
class Float | |
# Convert decimal to degrees, minutes, seconds sexagesimal | |
# (used for GPS coordinates) | |
def to_sexagesimal | |
degrees = abs.floor | |
x = (abs - degrees) * 60 | |
minutes = x.floor | |
seconds = (((x - minutes) * 60) * 100).round.to_f / 100 | |
sign = self < 0 ? '-' : '' | |
"#{sign}#{degrees}°#{minutes}'#{seconds}\"" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try this one instead:
You can test all possible DMS notations for roundtrip symmetry: