private async void OnTouchAsync(PinClickedEventArgs e) { try { LocationRestService restservice = new LocationRestService(); string label = e.Pin.Label; int pos = label.IndexOf(_topLocation, StringComparison.Ordinal); if (label.Contains(_topLocation) && pos >= 0) { label = label.Remove(0, _topLocation.Length); } Location location = await restservice.ReadLocationByNameAsync(label); if (location != null) { restservice.UpdateHits(location); var page = new DescPage { Location = location, User = User }; await Navigation.PushAsync(page); } else { await UpdateLocationsOnMap(); } } catch (FaultException <Exception> exc) { await DisplayAlert("Fejl", exc.Message, "OK"); } }
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"); } }
private async void OurEntry_OnCompleted(object sender, EventArgs e) { try { List <Location> combinedList = new List <Location>(); LocationRestService restService = new LocationRestService(); var locationListVar = await restService.ReadLocationByTagNameAsync(OurEntry.Text); var locationVar = await restService.ReadLocationByNameAsync(OurEntry.Text); var locationListUserVar = await restService.GetLocationsByUserNameAsync(OurEntry.Text); if (locationListVar != null) { combinedList.AddRange(locationListVar); } if (locationVar != null) { combinedList.Add(locationVar); } if (locationListUserVar != null) { combinedList.AddRange(locationListUserVar); } if (combinedList.Count == 0) { var address = OurEntry.Text; var geocodeLocationList = await Geocoding.GetLocationsAsync(address); if (geocodeLocationList != null) { foreach (var geocodeLocationVar in geocodeLocationList) { var placemarks = await Geocoding.GetPlacemarksAsync(geocodeLocationVar.Latitude, geocodeLocationVar.Longitude); foreach (var placemark in placemarks) { if (!string.IsNullOrWhiteSpace(placemark.CountryName) && !string.IsNullOrWhiteSpace(placemark.Locality) && !string.IsNullOrWhiteSpace(placemark.PostalCode) && !string.IsNullOrWhiteSpace(placemark.Thoroughfare)) { string oldGeocodeDescription = ""; string geocodeLocationVarDescription = $"{placemark.CountryName}, " + $"{placemark.Locality}, " + $"{placemark.PostalCode}, " + $"{placemark.Thoroughfare} " + $"{placemark.SubThoroughfare} "; if (!oldGeocodeDescription.Equals(geocodeLocationVarDescription)) { Location locationFromLocationVar = new Location() { Latitude = geocodeLocationVar.Latitude, Longitude = geocodeLocationVar.Longitude, LocationDescription = geocodeLocationVarDescription }; //oldGeocodeDescription = geocodeLocationVarDescription; if (combinedList.Count <= 10 && combinedList.Count > 0) { foreach (var locationFromLocationVarInCombinedList in combinedList) { if (Math.Abs(locationFromLocationVarInCombinedList.Latitude - locationFromLocationVar.Latitude) > 0.001 && Math.Abs(locationFromLocationVarInCombinedList.Longitude - locationFromLocationVar.Longitude) > 0.001) { combinedList.Add(locationFromLocationVar); } } } if (combinedList.Count == 0) { combinedList.Add(locationFromLocationVar); } } } } } } } if (combinedList.Count > 0) { SearchListView searchListView = new SearchListView { Locations = new ObservableCollection <Location>(combinedList) }; await Navigation.PushAsync(searchListView); } } 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"); } }