remoorejr / cordova-plugin-camera-with-exif

Cordova Camera Plugin that will return an image as well as the EXIF data (including GPS location) on iOS and Android devices.
Apache License 2.0
38 stars 53 forks source link

Android GPS Format #10

Closed maximilianloy closed 6 years ago

maximilianloy commented 8 years ago

Hi, the GPS data returned on Android is pretty weird. Is this normal?

{ aperture: "1.29" datetime: "2016:11:08 20:36:49" exposureTime: "0.083333335" flash: "65" focalLength: "3097/1000" gpsAltitude: "84000/100" gpsAltitudeRef: "0" gpsDateStamp: "2016:11:08" gpsLatitude: "45/1,30/1,4608/100" gpsLatitudeRef: "N" gpsLongitude: "10/1,18/1,1928/100" gpsLongitudeRef: "E" gpsProcessingMethod: null gpsTimestamp: "19:36:46" iso: "2773" make: "htc" model: "Nexus 9" orientation: "1" whiteBalance: "0" }

Tested it on Nexus 5 (Android 6.0.1) and Nexus 9 (Android 7.0)

pugwonk commented 8 years ago

(I'm just another random dev) I had the same issue - they're in degrees/minutes/seconds with optional multipliers. From a bit of research it's this that seems to be in the actual EXIF spec, though.

Here's some code I wrote to make sense of them...

    function EXIFtoLocation(stringDMS){
        function EXIFdivide(dStr) {
            num = dStr.split('/');
            return num[0] / num[1];
        }
        var DMS = stringDMS.split(",");

        return EXIFdivide(DMS[0]) + (EXIFdivide(DMS[1])/60) + (EXIFdivide(DMS[2])/3600);
    };

                if (metadata.GPS != null) { // iOS
                    // iPhone uses different fields
                    var lat = metadata.GPS.Latitude;
                    var lon = metadata.GPS.Longitude;
                    var latref = metadata.GPS.LatitudeRef;
                    var lonref = metadata.GPS.LongitudeRef;

                } else { // Android
                    var lat = EXIFtoLocation(metadata.gpsLatitude);
                    var lon = EXIFtoLocation(metadata.gpsLongitude);
                    var latref = metadata.gpsLatitudeRef;
                    var lonref = metadata.gpsLongitudeRef;

                }

                if (latref == "S")
                    lat = -lat;
                if (lonref == "W")
                    lon = -lon;

Agree though, it would be handy if some of this were in the plugin.

maximilianloy commented 8 years ago

I created PR #11 which fixes this on Android. There is actually already a function provided by the Android EXIF API to convert lat/lng and altitude. But good to know that I need to switch the sign on iOS too. I am testing in N/E so didn't notice this :-)

pugwonk commented 8 years ago

I've submitted a PR to your fork (hopefully that was the right way to do it!).

enokby commented 7 years ago

thanks man you're another dev who saved my life

manix commented 3 years ago

@pugwonk MVP