public async void DisplayImage() { await CrossMedia.Current.Initialize(); ImageInfo.TimeStamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); Plugin.Media.Abstractions.Location imageLocation; imageLocation = new Plugin.Media.Abstractions.Location(); try { var request = new GeolocationRequest(GeolocationAccuracy.Medium); var location = await Geolocation.GetLocationAsync(request); if (location != null) { imageLocation.Latitude = location.Latitude; imageLocation.Longitude = location.Longitude; ImageInfo.Coordinates = imageLocation.Latitude + ";" + imageLocation.Longitude; } } catch (FeatureNotSupportedException fnsEx) { // Handle not supported on device exception } catch (FeatureNotEnabledException fneEx) { // Handle not enabled on device exception } catch (PermissionException pEx) { // Handle permission exception } catch (Exception ex) { // Unable to get location } Photo = await CrossMedia.Current.TakePhotoAsync( new Plugin.Media.Abstractions.StoreCameraMediaOptions { SaveToAlbum = true, Directory = "cs191t", Name = imageFileName, Location = imageLocation, SaveMetaData = true, }); // Check file is available if (Photo != null) { CapturedImage = ImageSource.FromStream(() => { return(Photo.GetStream()); }); DiscardButton_isVisible = "True"; SaveButton_isVisible = "True"; } }
// handles the user picking a picture from their library async Task PickPicture() { if (!CrossMedia.Current.IsPickPhotoSupported) { return; } var file = await Plugin.Media.CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions { PhotoSize = Plugin.Media.Abstractions.PhotoSize.Medium, }); if (file == null) { return; } //grab the user path Post.PicturePath = file.Path.ToString(); // grab the time Post.PictureTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture); //grab location Plugin.Media.Abstractions.Location imageLocation; imageLocation = new Plugin.Media.Abstractions.Location(); try { var request = new GeolocationRequest(GeolocationAccuracy.Medium); var location = await Geolocation.GetLocationAsync(request); if (location != null) { imageLocation.Latitude = location.Latitude; imageLocation.Longitude = location.Longitude; Post.PictureLocation = "(" + imageLocation.Latitude + ", " + imageLocation.Longitude + ")"; } } catch (FeatureNotSupportedException fnsEx) { // Handle not supported on device exception } catch (FeatureNotEnabledException fneEx) { // Handle not enabled on device exception } catch (PermissionException pEx) { // Handle permission exception } catch (Exception ex) { // Unable to get location } }