Is there a way to access a Mac's geolocation from terminal? Some GUI apps use OS X location services, but I want to retrieve a Mac's physical location from the command line. This could be useful for running scripts, switching settings etc. The mechanism should be CoreLocation, not a Geo IP service (data too low-res, needs online connection).

Minimum requirement is output of longitude and latitude. Nice would be a number indicating the precision. Super nice: a geocoder that provides location names.
vilmoskörte's answer appears to be a good one, but I took it upon myself to make a tool that does this for my own education. I put it on GitHub.

WhereAmI

A simple command line tool. No options, just runs and outputs Lat/Long, accuracy in meters, and a timestamp. It will need OS X Location Services to be turned on (System Preferences > Security &amp; Privacy), and permission to gather your location (OS X will prompt you on first run).

Direct Download Link (.zip)