Parsing Android EXIF Coordinates in TypeScript
I found a fun little problem when working on a cross platform app that I recently released. Falconry Journal (Android, iOS)
When you inspect the EXIF data on iOS looking for geocode coordinates you get what you expect:
In the exif data you have a GPS object which has the fully formed longitude and latitude data that you can use as you expect, however when you look for that same data from an Android camera you get something a little unexpected:
The Android version requires you to do a little work if you need the traditional decimal value geocoordinates. If you want to understand what’s going on here, you might end up here: https://en.wikipedia.org/wiki/Geographic_coordinate_conversion and as confused and frustrated as myself.
To try and break it down as simply as I can (as well as I understand it) this output format is expressed as {degrees}/{denominator},{minutes}/{denominator},{seconds}/{divisor}
so this formula should convert it to decimal values is valid:
There is also the modifier of direction on each coordinate. So if GPSLatitudeRef
or GPSLongitudeRef
is ‘S’ or ‘W’ the decimal should be a negative number.
To put it all together, we come up with this function.
And finally, the sauce.
I hope this helps someone save some minutes or hours, and also prevents you from loading (yet another) NPM package to handle this simple yet confusing piece of logic!