Skip to content

Instantly share code, notes, and snippets.

@skeeto
Created November 30, 2011 01:20
Show Gist options
  • Save skeeto/1407517 to your computer and use it in GitHub Desktop.
Save skeeto/1407517 to your computer and use it in GitHub Desktop.
emacs lisp exercise: latitude-longitude-decimalize
;; http://xahlee.blogspot.com/2011/11/emacs-lisp-exercise-latitude-longitude.html
(defun latitude-longitude-decimalize (str)
(destructuring-bind (lath latm lats latd lonh lonm lons lond)
(split-string str "[^0-9.NEWS]+" t)
(vector (latlon-helper latd lath latm lats)
(latlon-helper lond lonh lonm lons))))
(defun latlon-helper (d &rest hms)
(* (if (or (equal d "N") (equal d "E")) 1 -1)
(reduce (lambda (a b) (+ b (/ a 60.0)))
(mapcar 'string-to-number (reverse hms)))))
;; Example usage:
(latitude-longitude-decimalize "37°26′36.42″N 06°15′14.28″W")
[37.44345 -6.253966666666667]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment