Forum Xamarin.iOS

What is the currently supported way to extract GPS data from an image picked from the gallery?

gaeliangaelian AUMember ✭✭
edited March 25 in Xamarin.iOS

I support a fairly old Xamarin.iOS app that needs to extract lat/long coordinates from images taken by the app. At some point the code we use to retrieve Exif data from a photo previously taken by the app and saved to the photo gallery stopped working. The image is apparently retrieved but the lat/long data is not present. I'm wondering if anyone can point me in the direction of what is the currently supported way to extract lat/long from images that have been saved to the gallery, as of iOS 13.

The lat/long data appears to be getting saved to the image, I've tried to verify this by using our app to take a photo then saving the resulting image from the gallery to the iOS Files app and looking at the Exif data there. In the Files app, I can see that the image has stored lat/long coordinates.

The code used to save the image to the gallery is this:

if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported)
    var location = new Plugin.Media.Abstractions.Location()
        Latitude = _lat, // _lat contains the expected value.
        Longitude = _long, // _long contains expected value.
        Altitude = _altitude,
        Timestamp = DateTime.UtcNow

    StoreCameraMediaOptions mediaOptions = new StoreCameraMediaOptions
        Directory = "MyApp",
        RotateImage = false,
        Location = location,
        SaveMetaData = true,
        SaveToAlbum = true

    _resultingPhoto = await CrossMedia.Current.TakePhotoAsync(mediaOptions);


The code used to retrieve the image from the gallery is this:

if (photoStatus == PermissionStatus.Granted)
    if (CrossMedia.Current.IsPickPhotoSupported)
        PickMediaOptions mediaOptions = new PickMediaOptions { RotateImage = true };
        _resultingPhoto = await CrossMedia.Current.PickPhotoAsync(mediaOptions);


The library that has been successfully used by the app for some time to extract the Exif data (but apparently no longer) is this one:

The exception thrown by this library when instantiating the ExifReader object is "Unable to locate EXIF content" and "Could not find Exif data block".

I thought it could be a problem with the library just being no longer supported or out of date, so I've also tried ExifLib.PCL (, as outlined in this answer on SO: I don't get an exception, but the resulting lat/long double arrays appear to contain only zeros.

Any help much appreciated.


Sign In or Register to comment.