I am writing a bash script that renames files based on EXIF headers. exiftool returns the following GPS Position string, which I need to format into Latitude/Longitude coordinates for use with Google Maps API.
GPS Position : 40 deg 44' 49.36" N, 73 deg 56' 28.18" W
Google Maps:
https://maps.googleapis.com/maps/api/geocode/json?latlng=40.7470444,-073.9411611
This is my code
awk -v FS="[ \t]" '{print $0,substr($1,length($1),1)substr($2,length($2),1)}' $1 \
| sed 's/\xc2\xb0\([0-9]\{1,2\}\).\([NEWS]\)/ \1 0 \2/g;s/\xc2\xb0\([NEWS]\)/ 0 0 \1/g;s/[^0-9NEWS]/ /g' \
| awk '{if ($9=="NE") {printf ("%.4f\t%.4f\n",$1+$2/60+$3/3600,$5+$6/60+$7/3600)} \
else if ($9=="NW") {printf ("%.4f\t%.4f\n",$1+$2/60+$3/3600,-($5+$6/60+$7/3600))} \
else if ($9=="SE") {printf ("%.4f\t%.4f\n",-($1+$2/60+$3/3600),$5+$6/60+$7/3600)} \
else if ($9=="SW") {printf ("%.4f\t%.4f\n",-($1+$2/60+$3/3600),-($5+$6/60+$7/3600))}}'
I’m getting this error:
sed: RE error: illegal byte sequence
What I need is a valid awk command to strip the “deg” and NSEW text, and divide by 3600 and 60 per this post:
how to convert gps north and gps west to lat/long in objective c
40 deg 44' 49.36" N, 73 deg 56' 28.18" W > 40.7470444,-073.9411611
Please help!