fulldecent / corelocationcli

Command line program to print location information from CoreLocation
MIT License
217 stars 29 forks source link

Additional option to print decimal coordinates with N|S & E|W #18

Closed JayBrown closed 4 years ago

JayBrown commented 6 years ago

I know this is a weird question, because decimal coordinates are just negative for S & W, but some programs like sunwait need input as decimal, but with N|S and E|W, i.e. in the format 52.516667N 13.388889E instead of 52.516667 13.388889 for Berlin, and 40.7127N 74.0059W instead of 40.7127 -74.0059 for NYC, et cetera. (Same for N vs. S.) I guess I can always parse CoreLocationCLI's output and change it myself, but maybe it isn't too complicated to add an option for an alternate output, e.g. CoreLocationCLI -orientation or CoreLocationCLI -o.

fulldecent commented 6 years ago

Thanks for sharing. Generally I prefer to use documented standards for output formats. Is there any documentation (ISO/IETF/etc.) where this is a preferred format?

JayBrown commented 6 years ago

Can't say. I just stumbled across sunwait today, and it seems to accept only this non-standard format.

JayBrown commented 6 years ago

It's easy to convert, though:

loc=$(CoreLocationCLI)
lat=$(echo "$loc" | awk '{print $1}')
long=$(echo "$loc" | awk '{print $2}')
[[ $lat == "-"* ]] && lat="$lat"S || lat="$lat"N
[[ $long == "-"* ]] && long="$long"W || long="$long"E
echo "$lat $long" | sed -e 's/-//g'
fulldecent commented 4 years ago

Thanks for reporting this. For now I believe non-standard GPS representations should be outside the scope of this project. But you do have a nice workaround.

And of course, awk can do all kinds of stuff, and even more golfing can be done on top of the below

echo '-45.356 -15' | awk '{print ($1>0) ? $1"N" : -$1"S"}'
echo '-45.356 -15' | awk '{print ($2>0) ? $2"E" : -$2"W"}'