// GeoTag the given file private async void GeoTagImageFile(IStorageFile image) { if (_geo != null) { await GeotagHelper.SetGeotagFromGeolocatorAsync(image, _geo); } }
private async void SetGeotagFromGeolocatorButton_Click() { // Call RequestAccessAsync from the UI thread to get user permission on location usage. // Otherwise SetGeotagFromGeolocator will fail. GeolocationAccessStatus status = await Geolocator.RequestAccessAsync(); if (status != GeolocationAccessStatus.Allowed) { rootPage.NotifyUser("Location access is not allowed", NotifyType.ErrorMessage); return; } Geolocator geolocator = new Geolocator(); geolocator.DesiredAccuracy = PositionAccuracy.High; try { await GeotagHelper.SetGeotagFromGeolocatorAsync(file, geolocator); rootPage.NotifyUser("Geolocation set to current location", NotifyType.StatusMessage); } catch (Exception ex) { // File I/O errors are reported as exceptions. // AccessDeniedExcetion can be raised if the user revoked location access // after RequestAccessAsync completed. rootPage.NotifyUser("Exception: " + ex.Message, NotifyType.ErrorMessage); } }
private async void SetGeoDataFromGeolocator(StorageFile imageFile) { // <SnippetSetGeoDataFromGeolocator> var locator = new Geolocator(); // Shows the user consent UI if needed var accessStatus = await Geolocator.RequestAccessAsync(); if (accessStatus == GeolocationAccessStatus.Allowed) { await GeotagHelper.SetGeotagFromGeolocatorAsync(imageFile, locator); } // </SnippetSetGeoDataFromGeolocator> }
private async Task SetGeotagFromGeolocatorAsync() { try { StorageFile file = await KnownFolders.PicturesLibrary.GetFileAsync(filename.Text); Geolocator geolocator = new Geolocator(); geolocator.DesiredAccuracy = PositionAccuracy.High; await GeotagHelper.SetGeotagFromGeolocatorAsync(file, geolocator); LogStatus("SetGeotagFromGeolocatorAsync complete"); } catch (Exception e) { LogError("Exception: " + e.Message); } }