private async void SeeMyLocationsButton_OnClicked(object sender, EventArgs e)
        {
            try
            {
                LocationRestService restService      = new LocationRestService();
                List <Location>     userLocationList = await restService.GetLocationsByUserNameAsync(User.UserName);

                SearchListView searchListView = new SearchListView
                {
                    Locations            = new ObservableCollection <Location>(userLocationList),
                    IsUserLocationSearch = true
                };
                await Navigation.PushAsync(searchListView);
            }
            catch (FaultException <Exception> exc)
            {
                await DisplayAlert("Fejl", exc.Message, "OK");
            }
        }
예제 #2
0
        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");
            }
        }