## How to modify GPS Information

For example, I want to modify "Exif.GPSInfo.GPSLatitude" ,its type is RATIONAL , but the latitude is expressed as three RATIONAL values giving the degrees, minutes, and seconds, respectively. How can I modify three RATIONAL values for the "Exif.GPSInfo.GPSLatitude".

### Replies (9)

#### RE: How to modify GPS Information - Added by Andreas Huggelover 6 years ago

Hi Mark,

If you're using the exiv2 command line tool, see here: http://dev.exiv2.org/boards/3/topics/1163?r=1165#message-1165
If you're using the C++ API, see this example: http://exiv2.org/example2.html

Cheers,
Andreas

#### RE: How to modify GPS Information - Added by Mark Allenover 6 years ago

Thank you very much! I solve this problem.

#### RE: How to modify GPS Information - Added by Mark Allenover 6 years ago

Thank you very much! I have solved this problem.

#### RE: How to modify GPS Information - Added by Francois Laverdureabout 6 years ago

I thought I'd simply re-use the same thread as I'm having a similar problem...

I'm currently writing a script and the GPS info is giving me a headache.
So far, I set the value for both longitude and latitude like this

set Latitude = "45/1,32/1,130020/10000"

in my batch file. Then I write a whole bunch of stuff to a file that contains the whole set of commands I want to put in the jpg like so

and then run the entire command list like this

exiv2 -m "%temp%\Commands.txt" "%~1"*.jpg

only to have exiv2 return this dreaded

Warning: Exif.GPSInfo.GPSLatitude: Failed to read Rational value ""

I tried changing the commas to spaces but it still doesn't work. I know the fractions give me the proper values for the location...
What am I doing wrong?

#### RE: How to modify GPS Information - Added by Francois Laverdureabout 6 years ago

I forgot to say that all my variables in the add section are presented between % percent marks... it's just that the forum won't show them.

#### RE: How to modify GPS Information - Added by Robin Millsabout 6 years ago

You have to validate the data in temp/Commands.txt. That's not so tough. You can run exiv2 -m c:\Users\yourname\path\to\temp\Commands.txt foo.jpg. If you get the dreaded warning from the command-prompt, your error must be in Commands.txt. (keep away from magic like temp when you debug this).

Once you know that Commands.txt is good, you have to be certain that the command arguments you pass to exiv2 are the arguments you intended to pass! All those special characters such as % and ~ can result in broken commands. I've found a little program args.cpp very useful. I've discussed it here: http://dev.exiv2.org/boards/3/topics/2066?r=2067#message-2067

A cup of coffee might help. Going out for a run always helps. Relax and you'll find how to get this working. And don't forget to report your solution as this will help another user one day.

#### RE: How to modify GPS Information - Added by Francois Laverdureabout 6 years ago

OK, you're right, my bad coding at work...
I just figured out that there is an error in the tag explanation page on the main site. No commas must be used.

Second, I had inserted a space before the = sign by accident... and it screwed up the whole thing.
So here's my take on it.

when you set the values in a batch file, this is what the tag should look like

set Latitude="45/1 32/1 130020/10000"

Notice, no spaces on each side of the equal (I don't know why I put some there initially) and the values are in dd/1 for degrees mm/1 for minutes. The seconds are often given in decimal. In my case, it was 13.0020 seconds. Since the program doesn't support decimals, you have to convert it into a full fraction. The simplest is to multiply the seconds and then re-divide by that number in the rational code. So 13.0020 seconds becomes 130020/10000 same thing just a different notation. The divided by part doesn't need to be a factor of 10, it just makes things easier to calculate.

As for writing to the commands.txt file that I use, it just works like usual with
echo add Exif.GPSInfo.GPSLatitude %Latitude%

I hope that helps someone...

#### RE: How to modify GPS Information - Added by Robin Millsabout 6 years ago

Glad to hear that this has a happy ending. And thanks for explaining how you got it to work. Very good. Take the rest of the day off!

#### RE: How to modify GPS Information - Added by Francois Laverdureabout 6 years ago

Sadly, I can't take the rest of the day off... I'm waiting for a visit from the men in brown (namely UPS) that's going to bring some long awaited memory chips (I ordered them back in September and the store has been dragging its feet ever-since).

(1-9/9)