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

Arjun Sharma picture Arjun Sharma · Dec 27, 2013 · Viewed 12.2k times · Source

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

enter image description here

 void cam_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {

                Image cameraImage = new Image();
                BitmapImage bImage = new BitmapImage();

                bImage.SetSource(e.ChosenPhoto);
                cameraImage.Source = bImage;

                e.ChosenPhoto.Position = 0;

                ExifReader reader = new ExifReader(e.ChosenPhoto);
                double gpsLat, gpsLng;

                reader.GetTagValue<double>(ExifTags.GPSLatitude,
                                                    out gpsLat))

                reader.GetTagValue<double>(ExifTags.GPSLongitude,
                                                    out gpsLng))


                MessageBox.Show(gpsLat.ToString() + "" + gpsLng.ToString());   

            }
        }

so that we can detect location where the image was taken. Please help to find the these property.

Answer

Sam picture Sam · Jan 30, 2015

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.