Skip to content

Instantly share code, notes, and snippets.

@ashaw
Created June 5, 2014 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashaw/ecf22e0cc861d5f84214 to your computer and use it in GitHub Desktop.
Save ashaw/ecf22e0cc861d5f84214 to your computer and use it in GitHub Desktop.
def dms_to_coord(dms, latlng)
re = latlng == 'lat' ? /^([\d]{2})([\d]{2})([\d]{2}(?:\.[\d]+)?)/ : /^([\d]{3})([\d]{2})([\d]{2}(?:\.[\d]+)?)/
q = dms.split(re)
q.shift
d, m, s = q.map(&:to_f)
res = d + m / 60 + s / 3600
#yolo
latlng == 'lng' ? "-#{res}" : res
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment