Its not too hard to add GPS capability to the Universal Windows SDK Camera sample so that captured images can have GPS information embedded in them.  .  Here’s how.

 

The Windows 10 SDK Samples are on GitHub.  The zipped version  is here: Download Zip

The sample app I am working with here is the  Basic camera app sample: 

Basic camera app sample features

This sample applies an end-to-end approach to demonstrate how to write a camera application using the Windows.Media.Capture API in conjunction with orientation sensors to cover the functions that most camera apps will require.

Specifically, the sample will covers how to:

  1. Manage the MediaCapture object throughout the lifecycle of the app and through navigation events.
  2. Acquire a camera located on a specific side of the device. In this case, the sample attempts to get the rear camera.
  3. Start and stop the preview to a UI element, including mirroring for front-facing cameras.
  4. Take a picture to a file, and disable the video capture button if the app is running on a device that doesn't support concurrent capturing of photos and video.
  5. Record a video to a file, and disable the photo capture button if the app is running on a device that doesn't support concurrent capturing of photos and video.
  6. Handle rotation events for both, the device moving in space and the page orientation changing on the screen. Also apply any necessary corrections to the preview stream rotation and to captured photos and videos.
  7. Handle MediaCapture RecordLimitationExceeded and Failed events to be notified that video recording needs to be stopped due to a video being too long, or clean up the MediaCapture instance when an error occurs.

 

About

I took the sample code (C#) and morphed it into a separate XAML page for an app that I was developing.  The CameraPage is called from another XAML page. I then wanted to add two things:

  1. Optional Camera Flash
  2. Embedded GPS Coordinates into photos

This blog covers the second issue. The previous blog covered the first one.

 

 

 

        private static async Task ReencodeAndSavePhotoAsync(IRandomAccessStream stream, PhotoOrientation photoOrientation)
        {
            using (var inputStream = stream)
            {
                var decoder = await BitmapDecoder.CreateAsync(inputStream);
                try
                {
                    var file = await KnownFolders.PicturesLibrary.CreateFileAsync(PixFilePath, CreationCollisionOption.GenerateUniqueName);

                    using (var outputStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                    { //This code removed for simplicity here but is required.  See the SDK sample code.


} //Add from here ---------------------------------------- try { if (GPSAndMappingPage._Geolocator == null) GPSAndMappingPage._Geolocator = new Geolocator(); if (GPSAndMappingPage._Geolocator != null) { // Request access to location (causes a user prompt the first time) GeolocationAccessStatus status = await Geolocator.RequestAccessAsync(); if (status == GeolocationAccessStatus.Allowed) { await GeotagHelper.SetGeotagFromGeolocatorAsync(file, GPSAndMappingPage._Geolocator); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Camera-ReencodeAndSavePhotoAsync2: " + ex.Message); } //To here ---------------------------------------------
}
catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Camera-ReencodeAndSavePhotoAsync1: " + ex.Message); } } }

The addityional GPS encoding code is placed in ReencodeAndSavePhotoAsync().

 

You need to add GPS capability via the AppManifest.

 

After the image file is created and the image is stored in it, the Geolocator (if available) is used get GPS information and store it as meta information in the file
.