Posted 2024/12/23
Show your current location in Emacs OSM mode
If you’ve got osm.el installed, and a GPS dongle running under gpsd, you can show your current location on a map with the following function:
(defun show-current-location-map ()
"Get your current location and show it on the map"
(interactive)
(let* ((s (split-string (shell-command-to-string "gpspipe -w -n 10 2> /dev/null | grep -m 1 TPV | jq '.lat, .lon' | tr '\n' ' '")))
(lat (string-to-number (string-trim (car s))))
(lon (string-to-number (string-trim (cadr s)))))
(osm-goto lat lon 16)
(delete-other-windows)))
I’ve bound it to C-x l
:
(global-set-key (kbd "C-x l") #'show-current-location-map)
Why? Well, aside from being neat, it’s also useful in wearable computing contexts… more on that later.