Get my computer's current city and state from terminal

Command line tool

I've made quick modification to an excellent robmathers app WhereAmI. You can find it on my github.

Once You compile it and run, that's the output:

Latitude: 40.714232
Longitude: -73.9612889
Accuracy (m): 65.000000
Timestamp: 30.04.2015, 11:37:45 CEST
Location: 277 Bedford Avenue, Brooklyn, NY 11211, United States

If You want only the city and the country - changes in parsing json should be made (or grep the output). Sample json data can be found here.

Note: This is very quick implementation, but there shouldn't be any errors

Info from preferences

You can get info from preferences by running:

defaults read /Library/Preferences/.GlobalPreferences.plist com.apple.preferences.timezone.selected_city

You'll need to parse the output, because it looks like:

{
CountryCode = PL;
GeonameID = 3081368;
Latitude = "51.1";
LocalizedNames =     {
    pl = "Wroc\\U0142aw";
};
Longitude = "17.03333";
Name = "Wroc\\U0142aw";
Population = 634893;
TimeZoneName = "Europe/Warsaw";
Version = 1;
}