How to Fetch the Geotag details of the captured image or stored image in Windows phone 8

后端 未结 4 1004
说谎
说谎 2021-02-04 13:30

I want to fetch the information from the image regarding the Geolocation as shown in the image below

4条回答
  •  星月不相逢
    2021-02-04 13:59

    None of these answers seemed to be completely working and correct. Here's what I came up with using this EXIF library, which is also available as a NuGet package.

    public static double[] GetLatLongFromImage(string imagePath)
    {
        ExifReader reader = new ExifReader(imagePath);
    
        // EXIF lat/long tags stored as [Degree, Minute, Second]
        double[] latitudeComponents;
        double[] longitudeComponents;
    
        string latitudeRef; // "N" or "S" ("S" will be negative latitude)
        string longitudeRef; // "E" or "W" ("W" will be a negative longitude)
    
        if (reader.GetTagValue(ExifTags.GPSLatitude, out latitudeComponents)
            && reader.GetTagValue(ExifTags.GPSLongitude, out longitudeComponents)
            && reader.GetTagValue(ExifTags.GPSLatitudeRef, out latitudeRef)
            && reader.GetTagValue(ExifTags.GPSLongitudeRef, out longitudeRef))
        {
    
            var latitude = ConvertDegreeAngleToDouble(latitudeComponents[0], latitudeComponents[1], latitudeComponents[2], latitudeRef);
            var longitude = ConvertDegreeAngleToDouble(longitudeComponents[0], longitudeComponents[1], longitudeComponents[2], longitudeRef);
            return new[] { latitude, longitude };
        }
    
        return null;
    }
    

    Helpers:

    public static double ConvertDegreeAngleToDouble(double degrees, double minutes, double seconds, string latLongRef)
    {
        double result = ConvertDegreeAngleToDouble(degrees, minutes, seconds);
        if (latLongRef == "S" || latLongRef == "W")
        {
            result *= -1;
        }
        return result;
    }
    
    public static double ConvertDegreeAngleToDouble(double degrees, double minutes, double seconds)
    {
        return degrees + (minutes / 60) + (seconds / 3600);
    }
    

    Credit to Igor's answer for the helper method and geedubb's for the main method.

提交回复
热议问题