private async void PlaceMarker(MapClickedEventArgs e) { try { var answer = await DisplayAlert("Marker", "Would you like to place a marker", "Yes", "No"); string geocodeAddress = ""; string nameMarker = "Unnamed location"; string urlMarker = "http://dmax0917.hegr.dk/img.png"; if (answer) { var lat = e.Point.Latitude; var lon = e.Point.Longitude; var placemarks = await Geocoding.GetPlacemarksAsync(lat, lon); var placemark = placemarks?.FirstOrDefault(); if (placemark != null) { geocodeAddress = $"{placemark.Thoroughfare}, " + $"{placemark.PostalCode} " + $"{placemark.Locality}, " + $"{placemark.CountryName}"; var nameAnswer = await DisplayAlert("Marker", "Would you like to give the marker a name?", "Yes", "No"); if (nameAnswer) { try { PromptResult pResult = await UserDialogs.Instance.PromptAsync(new PromptConfig { InputType = InputType.Name, OkText = "Add", Title = "Enter name", }); if (pResult.Ok && !string.IsNullOrWhiteSpace(pResult.Text)) { nameMarker = pResult.Text; } } catch (FaultException <Exception> exc) { await DisplayAlert("Fejl", exc.Message, "OK"); } } var imageAnswer = await DisplayAlert("Marker", "Would you like to give the marker an image?", "Yes", "No"); if (imageAnswer) { PromptResult pResult = await UserDialogs.Instance.PromptAsync(new PromptConfig { InputType = InputType.Name, OkText = "Add", Title = "Enter imageurl", }); if (pResult.Ok && !string.IsNullOrWhiteSpace(pResult.Text)) { urlMarker = pResult.Text; } } } GoogleMap.Pins.Add(new Pin { Label = geocodeAddress, Position = new Position(e.Point.Latitude, e.Point.Longitude) }); } Location location = new Location() { LocationName = nameMarker, Latitude = e.Point.Latitude, Longitude = e.Point.Longitude, LocationDescription = geocodeAddress, User = User, Pictures = new List <Picture>() }; Picture picture = new Picture() { Url = urlMarker }; location.Pictures.Add(picture); ILocationRestService restService = new LocationRestService(); await restService.Create(location); //To be added: InfoWindow that contain most of the description and are tied to markers.. } catch (FaultException <Exception> exc) { await DisplayAlert("Fejl", exc.Message, "OK"); } }
async void Handle_ItemTapped(object sender, ItemTappedEventArgs e) { try { LocationViewModel locationViewModel = (LocationViewModel)e.Item; Location location = locationViewModel.Location; if (IsUserLocationSearch) { EditLocationPage editLocationPage = new EditLocationPage { Location = location }; editLocationPage.SetPlaceholders(); await Navigation.PushAsync(editLocationPage); } else if (IsUserCommentSearch && User != null) { EditRatingPage editRatingPage = new EditRatingPage { Rating = location.Ratings.Find(x => x.User.UserId == User.UserId) }; editRatingPage.SetPlaceholders(); await Navigation.PushAsync(editRatingPage); } else { var itemTappedAnswer = await DisplayAlert("Lokation", "What do you want to do?", "Go to location", "Add location"); if (itemTappedAnswer) { MainPage mainPage = new MainPage(); await Navigation.PushAsync(mainPage); mainPage.GoToLocation(location.Latitude, location.Longitude); Debug.WriteLine("Gå til " + location.Latitude + " " + location.Longitude); } if (!itemTappedAnswer) { try { string geocodeAddress; var placemarks = await Geocoding.GetPlacemarksAsync(location.Latitude, location.Longitude); var placemark = placemarks?.FirstOrDefault(); if (placemark != null) { geocodeAddress = $"{placemark.CountryName}, " + $"{placemark.Locality}, " + $"{placemark.PostalCode}, " + $"{placemark.Thoroughfare} "; try { PromptResult pResult = await UserDialogs.Instance.PromptAsync(new PromptConfig { InputType = InputType.Name, OkText = "Add", Title = "Enter name for the location", }); if (pResult.Ok && !string.IsNullOrWhiteSpace(pResult.Text)) { location.LocationName = pResult.Text; } } catch (Exception exception) { Console.WriteLine(exception.StackTrace); } } } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } ILocationRestService restService = new LocationRestService(); await restService.Create(location); } } //Deselect Item ((ListView)sender).SelectedItem = null; } catch (FaultException <Exception> exc) { await DisplayAlert("Fejl", exc.Message, "OK"); } }