1

I am adding GPS coordinates within the EXIF header of my JPG's, and saving them to the camera roll. And for some strange reason, when I view the JPG EXIF information afterwards using a third party app, the decimal lat/long coordinates have been truncated, and I lose my location accuracy.

example:

[GPSDictionary setObject:[NSNumber numberWithDouble:12.34567890]
                      forKey:(NSString*)kCGImagePropertyGPSLatitude];

Results in:

"{GPS}" = {
     Latitude = "12.3456789";
};

But this is what actually ends up within the EXIF header of the JPG file:

Latitude = "12.34566667";

Other times it's worse.

iPhone GPS: Longitude = 79.78598345
EXIF   GPS: Longitude = 79.786

How can I prevent iOS from mangling my coordinates bits?

As this affects the accuracy of calculations later on.

Sebastian Dwornik
  • 2,446
  • 2
  • 32
  • 54
  • A latitude or longitude with 8 decimal places pinpoints a location to within 1 millimetre (or about 1/16 of an inch). Do you really require this level of precision (I don't believe your input data is this accurate). Also, this looks like a issue where floating point decimal numbers cannot be exactly represented by a floating point binary. There are other posts on SO on this issue. See: http://stackoverflow.com/q/1089018/558933 – Robotic Cat Nov 02 '12 at 03:33
  • I shortened one of my Latitude values to be more accurate of what is printed during NSLog. And I would expect that exact same value string to be saved in the EXIF header. As I'll take every bit of precision I can get. – Sebastian Dwornik Nov 02 '12 at 03:41

1 Answers1

2

The most likely explanation is that the culprit is the application that you used to write the Exif information, rather than the one you used later to read the Exif information.

The Exif v2.3 standard (http://www.cipa.jp/std/documents/e/DC-008-2012_E.pdf) says that GPS latitude and longitude are stored as 3 values of type RATIONAL, one for degrees, one for minutes, and one for seconds. A value of type RATIONAL expresses a ratio of two unsigned 32-bit integer numbers. So, a decimal latitude or longitude must be converted into degrees, minutes, and seconds, and each of those must be expressed as a ratio, which means a particular denominator must be chosen for them. The denominator of the smallest used unit determines the resolution, and is chosen by the designer of the application that writes the Exif header.

The longitude and latitude truncations that you mention are consistent with the choice of expressing the coordinates in units of 1/100th of an arc minute. Your latitude of 12.3456789 degrees corresponds to 12 degrees and 20.740734 arc minutes, which rounds to 12 degrees and 2074/100 arc minutes, which corresponds to the 12.3456666... degrees that you got. Your longitude of 79.78598345 degrees corresponds to 79 degrees and 47.159007 arc minutes, which rounds to 79 degrees and 4716/100 arc minutes, which corresponds to the 79.786 degrees that you got.

If you need greater resolution, then you should see if the application that you've been using to write the Exif header can be configured to use greater resolution, or else use a different application to write the Exif information that uses greater resolution. For example, if I use exiftool (http://owl.phy.queensu.ca/~phil/exiftool/) to write your original GPS longitude and latitude to the Exif header of an image, and then use exiftool again to extract and print the coordinates, then I get 12.3456789000111 and 79.7859834499989 degrees, respectively, of which the difference relative to the original coordinates imply a resolution about a million times better than what was provided by the application that you used.

Louis Strous
  • 734
  • 7
  • 13
  • The 000111 and 99989 suffixes look more like rounding "errors", not actual accuracy. You'd have to do a round-trip comparison with meaningful figures in those digits in order to prove your claim about "a resolution about a million times better" – Asteroids With Wings Jun 04 '20 at 19:48
  • You are correct, based on the given numbers the improvement might be only about a factor of 1667 (the ratio between 0.01 arc minute and 1e-7 degrees). – Louis Strous Jun 05 '20 at 18:05
  • If with exiftool I set the longitude to 12.345678912345 and then use exiftool to print the longitude then I get 12.34567891230000036273, so exiftool uses a resolution of 1e-10 degrees. The improvement compared to the OP's results is the ratio of 0.01 arc minute and 1e-10 degrees, which is a factor of about 1.7 million. – Louis Strous Jun 05 '20 at 18:07