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:
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:
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:
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.