How to parse EXIF GPS information to lat,lng decimal numbers

EXIF stores GPS coords as rational64u which is a list of six unsigned whole numbers in the following order:

[
   degreesNumerator, degreesDenominator, 
   minutesNumerator, minutesDenominator, 
   secondsNumerator, secondsDenominator
]

The format is consistent, and it looks like the tool you are using has already divided each pair into decimal numbers, so what you have is:

Lat: 55°   40.711' 0"
Lng:  8°  30.2282' 0"

If you want to convert to a single decimal number:

= Degrees + Minutes/60 + Seconds/3600

According to this page, the latitude and longitude values could be in (1) degrees, (2) degrees and decimal minutes, or (3) degrees, minutes, and decimal seconds.

In your example, (2) is a decimal value and (3) is zero, so you have degrees, decimal minutes.

So, you'll have to some checks on the three values to determine which format is being used.


Exiftool will output the coordinates in low precision decimal if you use the -n switch. You can get more precision with -c switch and give the desired quantity of digits behind the decimal:

exiftool -c '%.6f' -GPSPosition filename.jpg

Shows position with 6 digits behind the decimal, which is good for finding a place within 5 inches.

Tags:

Gps