Store tags in variables

Started by davidcpreston, March 07, 2025, 03:58:25 PM

Previous topic - Next topic

davidcpreston

Windows 11 batch file Exiftool 13.22
Every time I think I'be got a grasp of this something else confounds me, and I'm sure this mis simple.
This works except for storing the tags in the variables. I've set the variables to a known location to ensure the actual command is working. I know I don't need the variables in %% when I'm setting them, but I've tried without, enclosing in single and double quotes and can't find an example that actually does it:-

rem Open File in Google Maps with GPS Lat/Long from file dropped on batch file
echo %1
set latitude=54.9934303333333
set longitude=-2.13724472222222
echo %latitude%,%longitude%
exiftool -n -gpslatitude>%latitude% -gpslongitude>%longitude% -if "$gpslatitude" %1
echo %latitude%,%longitude%
pause
start "Google Maps" "https://www.google.com/maps/search/?api=1&query=%latitude%,%longitude%"
start "Google Maps" "https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=%latitude%,%longitude%"
pause

Phil Harvey

Hi David,

Just a few issues...

First of all, your ">" is pointing the wrong way.

Second, the ">" must be quoted or the shell will interpret it as a redirection.

Third, you shouldn't be using ">" or "<" anyway because this is a simple assignment.  Use "=" instead.

Fourth, don't you want to do this if GPSLatitude does not exist?

Fifth, you don't need the -n option.

Sixth, you should also be setting the reference directions.  (I'll do this using a wildcard.):

exiftool -gpslatitude*=%latitude% -gpslongitude*=%longitude% -if "not $gpslatitude" %1

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

davidcpreston

What you are proposing is that I set the gps tags in the jpg from variables?

What I want to do is extract gpslatitude and gpslongitude from the jpg to build the command to show the location the photo was taken in Google Maps, so I will only do it if gpslatitude exists in the jpg

StarGeek

Quote from: davidcpreston on March 07, 2025, 04:31:13 PMWhat I want to do is extract gpslatitude and gpslongitude from the jpg

I'm definitely confused as you are setting the variables beforehand.

To set variables from a JPEG, you would have to capture the exiftool output and extract the data from that. Exiftool cannot directly set a Windows batch variable.

Another option would be to use the GPS2MapUrl.config file I made.

Example
C:\>exiftool -config GPS2MapUrl.config -G1 -a -s -*url y:\!temp\Test4.jpg
[Composite]     BingMapsUrl                     : https://bing.com/maps/?cp=54.9934303333333~-2.13724472222222&lvl=16
[Composite]     GoogleMapsUrl                   : https://www.google.com/maps/search/?q=54.9934303333333,-2.13724472222222
[Composite]     MapquestMapsUrl                 : https://www.mapquest.com/search/54.9934303333333%20-2.13724472222222
[Composite]     OpenStreetMapsUrl               : https://www.openstreetmap.org/?mlat=54.9934303333333&mlon=-2.13724472222222
[Composite]     YandexMapsUrl                   : https://yandex.com/maps/?ll=-2.13724472222222%2C54.9934303333333&text=54.9934303333333%2C-2.13724472222222

Testing now, it looks like the MapQuest one is broken. Or it may be that MapQuest doesn't like that coordinate. See the note under revision 1.2.

OpenStreetMapsUrl has the location, but needs to be zoomed in a bit. YandexMapsUrl is also broken, but looks like an easy fix.

Since you've shown me how to create a street view URL, I can create a tag for that if desired. Though the api=1 breaks the links for me.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

After some searching, you could also use something like this.

for /F "tokens=*" %i in ('exiftool -p "https://www.google.com/maps/search/?api=1&query=$GPSLatitude#,$GPSLongitude#" file.jpg ') do start %i

If you use a bat file, make sure and read FAQ #27, My ExifTool command doesn't work from a Windows .BAT file.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

I misunderstood completely, but StarGeek to the rescue. :)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

davidcpreston

Thanks guys,
The last option that Stargeek provided is what I was looking for.
I don't need to use variables, but it's what I'm used to doing in the Windows environment I'm familiar with.
If you have access to Windows and copy and paste what I posted into a .bat file and drop a jpg on it, it will work.
I only set them at the beginning to test that it worked, before adding the EXIFTOOL command to get the lat and long.
I have actually compiled an exe written in VB.net in Visual Studio some years ago that does a binary read of a JPG to extract the lat and long, but it uses libraries that are now unsupported, so though I'd use EXIFTOOL to replace it, but as you have witnessed I struggle with the syntax so thank you for your patience.

davidcpreston

#7
Thank you so much, it took a bit of faffing, but this works; the & also needs escaping but %1 doesn't:-

rem show marker at location in Google Maps
for /F "tokens=*" %%i in ('exiftool -p "https://www.google.com/maps/search/?api=1&&query=$GPSLatitude#,$GPSLongitude#" -if "$gpslatitude" %1 ') do start %%i

rem show pano (Street View) at location in Google Maps
for /F "tokens=*" %%i in ('exiftool -p "https://www.google.com/maps/@?api=1&&map_action=pano&&viewpoint=$GPSLatitude#,$GPSLongitude#" -if "$gpslatitude" %1 ') do start %%i
I was hoping to do something with -if "$gpslatitude" or -if "not $gpslatitude" to make it pause, goto or some other action but couldn't work it out. It's OK as it is, it just doesn't open Google Maps if the tag isn't found. It's very quick and easy to use.