LocateMe brings command-line access to Apple’s location APIs

For those of us that are not overly comfortable with Xcode and the C programming language, Robert Harder over at iHarder.net has kindly written an easy to use tool that lets a user find their latitude and longitude location from a command-line interface using Apple’s geolocation services.

The command has a number of options which you can find either at the end of this post, or by typing LocateMe -h at the command prompt.

This has a number of uses for bespoke remote monitoring solution. I had previously played around with geoiptool and checkip.dyndns.org, developing this script:

ip_address=`curl -s http://checkip.dyndns.org | sed ‘s/[a-zA-Z/<> :]//g’`
echo “IP address is $ip_address”
curl -s http://www.geoiptool.com/en/?IP=${IP} | textutil -convert txt -stdin -stdout -format html | sed -n ‘/Host Name/,/Postal code/p’
exit 0

This worked nicely and did not need any additionally installed software, but unfortunately was quite vague in its location.

The LocateMe tool’s output is the exact location of the device, making it a far more useful option.

To install the program, copy the LocateMe file to one of the pre-defined $PATH locations such as /usr/local/bin (or leave it in a “current directory” and call it with ./LocateMe).

USAGE: LocateMe [options]
Version: 0.2
Outputs your current location using Apple’s geolocation services.
-h This help message
-g Generate a Google Map URL
-l Generate long, multiline format
-f format Generate a custom output with the following placeholders
{LAT} Latitude as a floating point number
{LON} Longitude as a floating point number
{ALT} Altitude in meters as a floating point number
{SPD} Speed in meters per second as a floating point number
{DIR} Direction in degrees from true north as a floating point number
{HAC} Horizontal accuracy in meters as a floating point number
{VAC} Vertical accuracy in meters as a floating point number
{TIME} Timestamp (with date) of the location fix
{HOST} Computer hostname

Credit goes to Robert Harder at iHarder.net for the LocateMe program. You can find other useful scripts using LocateMe in the blog:

The LocateMe program can be downloaded here


Leave a Reply

Your email address will not be published. Required fields are marked *