bashshellgpsexiftoolgeotagging

How to set a JPEG's lat and lon coords with exiftool?


Using exiftool, if I have a file named foobar.jpeg and the shell variables lat="37.7708" and lon="-122.451".

What command do I use to set the EXIF metadata for that jpeg file such that its "geotag" / GPS metadata is set with those coordinates.


Solution

  • exiftool "-GPSLatitude=$lat" "-GPSLatitudeRef=$lat" "-GPSLongitude=$lon" "-GPSLongitudeRef=$lon" foobar.jpeg

    Because the GPS coordinates tags are unsigned, you need to make sure and assign the values to the relevant GPSLatitudeRef/GPSLongitudeRef tags as well, especially if the location is in the Western and/or Southern hemisphere. Even though these values would normally be set with N/S and E/W, exiftool well accept the raw values and figure out the proper Ref direction from that.