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

后端 未结 4 949
说谎
说谎 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:48

    You will need to read the EXIF data from the image.

    You can use a library such as this

    // Instantiate the reader
    ExifReader reader = new ExifReader(@"..path to your image\...jpg");
    
    // Extract the tag data using the ExifTags enumeration
    double gpsLat, gpsLng;
    if (reader.GetTagValue(ExifTags.GPSLatitude, 
                                        out gpsLat))
    {
        // Do whatever is required with the extracted information
        //...
    }
    if (reader.GetTagValue(ExifTags.GPSLongitude, 
                                        out gpsLng))
    {
        // Do whatever is required with the extracted information
        //...
    }
    

    UPDATE. Code changed to use MemoryStream

        void cam_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                using (MemoryStream memo = new MemoryStream())
                {
                    e.ChosenPhoto.CopyTo(memo);
                    memo.Position = 0;
                    using (ExifReader reader = new ExifReader(memo))
                    {
                        double[] latitudeComponents;
                        reader.GetTagValue(ExifTags.GPSLatitude, out latitudeComponents);
    
                        double[] longitudeComponents;
                        reader.GetTagValue(ExifTags.GPSLongitude, out longitudeComponents);
    
                        // Lat/long are stored as D°M'S" arrays, so you will need to reconstruct their values as below:
                        var latitude = latitudeComponents[0] + latitudeComponents[1] / 60 + latitudeComponents[2] / 3600;
                        var longitude = longitudeComponents[0] + longitudeComponents[1] / 60 + longitudeComponents[2] / 3600;
    
                        // latitude and longitude should now be set correctly...
                    }
                }
            }
        }
    

提交回复
热议问题