Ejemplo n.º 1
0
        private async void GeocodeButton_Click(object sender, RoutedEventArgs e)
        {
            // The address or business to geocode.
            string addressToGeocode = txbAddress.Text;
            // Geocode the specified address, using the specified reference point
            // as a query hint. Return no more than 3 results.
            MapLocationFinderResult result =
                await MapLocationFinder.FindLocationsAsync(
                    addressToGeocode,
                    null,
                    3);

            // If the query returns results, display the coordinates
            // of the first result.
            if (result.Status == MapLocationFinderStatus.Success)
            {
                var loc = result.Locations[0];
                ViewModel.InputLocation(loc.Point.Position.Latitude, loc.Point.Position.Longitude, loc.Address.FormattedAddress);
                DrawPoint(loc.Point.Position, "Nu geselecteerd");
            }
            else
            {
                ViewModel.ErrorMessage = "Deze locatie kon niet gevonden worden";
            }
        }
        async private void btnSzukaj_Click(object sender, RoutedEventArgs e)
        {
            var textCelu = tbCel.Text;

            if (textCelu != "")
            {
                Geopoint hintPoint             = new Geopoint(pktStart);
                MapLocationFinderResult result =
                    await MapLocationFinder.FindLocationsAsync(textCelu, hintPoint, 3);

                var dl_geogr   = result.Locations[0].Point.Position.Longitude;
                var szer_geogr = result.Locations[0].Point.Position.Latitude;

                pktKoniec.Latitude  = szer_geogr;
                pktKoniec.Longitude = dl_geogr;

                DaneGeograficzne.pktDocelowy        = pktKoniec;
                DaneGeograficzne.pktKoniecLatitude  = result.Locations[0].Point.Position.Latitude;
                DaneGeograficzne.pktKoniecLongitude = result.Locations[0].Point.Position.Longitude;

                if (result.Status == MapLocationFinderStatus.Success)
                {
                    tbDlug_cel.Text = "Długość geograficzna: " +
                                      dl_geogr;
                    tbSzer_cel.Text = "Szerokość geograficzna: " +
                                      szer_geogr;
                }
            }
            else
            {
                tbCel.Text = "Wprowadź poprawne dane lokalizacyjne";
            }
        }
        public async Task <string> GetCityName()
        {
            BasicGeoposition position = await GetUserPosition();

            Geopoint geopoint = new Geopoint(new BasicGeoposition
            {
                Latitude  = position.Latitude,
                Longitude = position.Longitude
            });

            try
            {
                MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(geopoint, MapLocationDesiredAccuracy.Low);

                if (result.Status == MapLocationFinderStatus.Success)
                {
                    return(result.Locations[0].Address.Town);
                }
            }
            catch (SEHException)
            {
                // Ignored
            }

            return(String.Format("({0}, {1})", position.Latitude, position.Longitude));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// The <c>MapTapped</c> method gets invoked, when the user taps on the <c>MapControl</c> provided by the <c>AddShop</c>-View.
        /// It gets the geographical position of the point, where the User tapped on the <c>MapControl</c>. With this position,
        /// the method estimates an address and saves the gathered values to its Properties (<c>Location</c> and <c>Address</c>).
        ///
        /// If there are no results for the address, the values for the Properties don't get set.
        /// </summary>
        /// <param name="sender">The <c>MapControl</c> provided by the View, which was tapped by the User.</param>
        /// <param name="args">Contains the geographical position of the point, where the User tapped on the <c>MapControl</c>.</param>
        public async void MapTapped(MapControl sender, MapInputEventArgs args)
        {
            try
            {
                // Set tapped Location as selected location
                Location = args.Location.Position;

                // Find corresponding address of the location
                MapLocationFinderResult FinderResult = await MapLocationFinder.FindLocationsAtAsync(args.Location);

                // Check, if any address has been found
                if (FinderResult.Status == MapLocationFinderStatus.Success && FinderResult.Locations.Count > 0)
                {
                    // Format and set address of the selected location
                    var    selectedLocation = FinderResult.Locations.First();
                    string format           = "{0} {1}, {2} {3}, {4}";

                    Address = string.Format(format,
                                            selectedLocation.Address.Street,
                                            selectedLocation.Address.StreetNumber,
                                            selectedLocation.Address.PostCode,
                                            selectedLocation.Address.Town,
                                            selectedLocation.Address.CountryCode);
                }
            }
            catch (Exception ex)
            {
                Address = string.Empty;
                dialogService.ShowMessage(
                    ResourceLoader.GetForCurrentView().GetString("FindAddressError"),
                    ResourceLoader.GetForCurrentView().GetString("ErrorTitle"));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Attempts to update either the address or the coordinates of the specified location
        /// if the other value is missing, using the specified current location to provide
        /// context for prioritizing multiple locations returned for an address.
        /// </summary>
        /// <param name="location">The location to update.</param>
        /// <param name="currentLocation">The current location.</param>
        public static async Task <bool> TryUpdateMissingLocationInfoAsync(LocationData location, LocationData currentLocation)
        {
            bool hasNoAddress = String.IsNullOrEmpty(location.Address);

            if (hasNoAddress && location.Position.Latitude == 0 && location.Position.Longitude == 0)
            {
                return(true);
            }

            var results = hasNoAddress ?
                          await MapLocationFinder.FindLocationsAtAsync(location.Geopoint) :
                          await MapLocationFinder.FindLocationsAsync(location.Address, currentLocation.Geopoint);

            if (results.Status == MapLocationFinderStatus.Success && results.Locations.Count > 0)
            {
                var result = results.Locations.First();
                //   location.Position = result.Point.Position;
                location.Address = result.Address.FormattedAddress;
                if (String.IsNullOrEmpty(location.Name))
                {
                    location.Name = result.Address.Town;
                }

                // Sometimes the returned address is poorly formatted. This fixes one of the issues.
                if (location.Address.Trim().StartsWith(","))
                {
                    location.Address = location.Address.Trim().Substring(1).Trim();
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
        async private void Host_GeoLocationChanged(Geopoint obj)
        {
            await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                var point    = obj;
                var location = $"LAT:{point.Position.Latitude}, ";
                location    += $"LONG:{point.Position.Longitude}";

                txt_location.Text = "searching ... ";
                try
                {
                    var location_results = await MapLocationFinder.FindLocationsAtAsync(point);

                    //since we are only interested in city and state info
                    //we only need the first item from the list
                    var location_result = location_results.Locations.FirstOrDefault();

                    if (location_result != null)
                    {
                        txt_location.Text = $"{location_result.Address.Town}, {location_result.Address.Region}";
                    }
                }
                catch
                {
                    txt_location.Text = "Location unknown";
                }
            });
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Helper Method - Updates GUI and CarPushpin
        /// </summary>
        private async void DrawCarPushPin(PositionChangedEventArgs args)
        {
            /*
             * if (MainMap.MapElements[0] != null) // removes previous car pushpin
             * {
             *  MainMap.MapElements.RemoveAt(0);
             * }
             */
            Geopoint ChangedPosition = new Geopoint(new BasicGeoposition()
            {
                Latitude  = args.Position.Coordinate.Latitude,
                Longitude = args.Position.Coordinate.Longitude
            });

            ParkdInformation = await MapLocationFinder.FindLocationsAtAsync(ChangedPosition);

            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                if (CarPushpin.Location != null) // already existing, remove and update
                {
                    MainMap.MapElements.Remove(CarPushpin);
                }
                else // not existing yet, first one
                {
                    CarPushpin.Title = "Parkit here?";
                    CarPushpin.NormalizedAnchorPoint = new Point(0.5, 1.0);

                    if (ParkdInformation != null)
                    {
                        string address = ParkdInformation.Locations[0].Address.BuildingName +
                                         ParkdInformation.Locations[0].Address.StreetNumber +
                                         ParkdInformation.Locations[0].Address.Street +
                                         ParkdInformation.Locations[0].Address.Town;
                        LocationTextBox.Text = address;
                    }
                }
                if (CarGeoposition != null)
                {
                    CarPushpin.Location = new Geopoint(new BasicGeoposition()
                    {
                        Latitude  = CarGeoposition.Coordinate.Latitude,
                        Longitude = CarGeoposition.Coordinate.Longitude
                    });
                }
                else
                {
                    CarPushpin.Location = ChangedPosition;
                }
                //MainMap.MapElements.Remove(CarPushpin);
                MainMap.MapElements.Add(CarPushpin);
                MainMap.Center         = CarPushpin.Location;
                MainMap.ZoomLevel      = MapZoom;
                MainMap.Height         = MapHeight;
                MainMap.Margin         = new Thickness(0, 0, 0, 0);
                LocationTextBox.Margin = new Thickness(0, 0, 0, 0);
                //MainSettings.AddOrUpdateValue("CarLocationKeyName", CarPushpin.Location);
                MainSettings.AddOrUpdateValue("CarLocationLatitudeKeyName", CarPushpin.Location.Position.Latitude);
                MainSettings.AddOrUpdateValue("CarLocationLongitudeKeyName", CarPushpin.Location.Position.Longitude);
            });
        }
Ejemplo n.º 8
0
        private async Task <SimpleLocation> ValidateLocationAsync(string location)
        {
            LogService.Write("Validating location...");
            try
            {
                var results = await MapLocationFinder.FindLocationsAsync(location, null);

                if ((results.Status == MapLocationFinderStatus.Success) && (results.Locations.Count != 0))
                {
                    var foundLocation = results.Locations[0];
                    LogService.Write($"Found location: {foundLocation.DisplayName}");

                    return(new SimpleLocation(foundLocation.DisplayName, foundLocation.Point.Position.Latitude, foundLocation.Point.Position.Longitude));
                }
                // Reset to default values so that weather page uses geolocation
                else if (string.IsNullOrWhiteSpace(location))
                {
                    LogService.Write("Location empty.");
                    return(EmptyLocation);
                }
                else
                {
                    LogService.Write("Invalid location.");
                    return(InvalidLocation);
                }
            }
            catch (Exception ex)
            {
                LogService.WriteException(ex);
                return(InvalidLocation);
            }
        }
        private async Task GetTown(double latitude, double longitude)
        {
            Debug.WriteLine("Entraste al metodo GetTown {0},{1}\n", latitude, longitude);
            try
            {
                BasicGeoposition location = new BasicGeoposition();
                location.Latitude  = latitude;
                location.Longitude = longitude;
                Geopoint pointToReverseGeocode = new Geopoint(location);
                MapLocationFinderResult result =
                    await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

                if (result.Status == MapLocationFinderStatus.Success)
                {
                    tbStreet.Text   = result.Locations[0].Address.Street;
                    tbDistrict.Text = result.Locations[0].Address.District;
                    tbTown.Text     = result.Locations[0].Address.Town;
                    tbCountry.Text  = result.Locations[0].Address.Country;
                    Debug.WriteLine("Town: " + result.Locations[0].Address.Town);
                    Debug.WriteLine("district: " + result.Locations[0].Address.District);
                    Debug.WriteLine("Country: " + result.Locations[0].Address.Country);
                    Debug.WriteLine("Street: " + result.Locations[0].Address.Street);
                    Mapping(latitude, longitude);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message.ToString());
            }
        }
Ejemplo n.º 10
0
    public async void OnTapAndHold(LatLonAlt latLonAlt)
    {
        if (ReferenceEquals(MapSession.Current, null) || string.IsNullOrEmpty(MapSession.Current.DeveloperKey))
        {
            Debug.LogError(
                "Provide a Bing Maps key to use the map services. " +
                "This key can be set on a MapSession component.");
            return;
        }

        var finderResult = await MapLocationFinder.FindLocationsAt(latLonAlt.LatLon);

        string formattedAddressString = null;

        if (finderResult.Locations.Count > 0)
        {
            formattedAddressString = finderResult.Locations[0].Address.FormattedAddress;
        }

        if (_mapPinPrefab != null)
        {
            // Create a new MapPin instance at the specified location.
            var newMapPin = Instantiate(_mapPinPrefab);
            newMapPin.Location = latLonAlt.LatLon;
            var textMesh = newMapPin.GetComponentInChildren <TextMeshPro>();
            textMesh.text = formattedAddressString ?? "No address found.";

            _mapPinLayer.MapPins.Add(newMapPin);
        }
    }
Ejemplo n.º 11
0
        public async void getPos()
        {
            Geolocator geolocator = new Geolocator {
                DesiredAccuracyInMeters = 1
            };

            Geoposition pos = await geolocator.GetGeopositionAsync();

            var longitud = (float)pos.Coordinate.Point.Position.Latitude;
            var latitud  = (float)pos.Coordinate.Point.Position.Longitude;
            // origin.Text =longitud.ToString();

            BasicGeoposition location = new BasicGeoposition();

            location.Latitude  = latitud;
            location.Longitude = longitud;
            Geopoint pointToReverseGeocode = new Geopoint(location);

            MapLocationFinderResult result =
                await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

            if (result.Status == MapLocationFinderStatus.Success)
            {
                origengps.Text = result.Locations[0].Address.Country;
            }
        }
Ejemplo n.º 12
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            var parameter = e.Parameter as string;

            Globals._email = parameter;
            System.Diagnostics.Debug.Write("\n line 55" + Globals._email);
            HttpClient httpClient = new HttpClient();

            Uri requestUri = new Uri("https://firsthellojunk.azurewebsites.net/api/FetchPatient?code=LBn9ZSPhn7U5ZsKYaC4ICiP5KX6v/tcpxj855db4Vh6p8lsR2FAHUA==&email=" + Globals._email + "&password=nopw");

            try
            {
                HttpResponseMessage response = await httpClient.GetAsync(requestUri);

                if ((int)response.StatusCode != 200)
                {
                    errormessage.Text = "patient info unavailable";
                }
                else
                {
                    var textResponse = await response.Content.ReadAsStringAsync();

                    var settings              = textResponse.Trim('"').Split(',');
                    var readsLatitude         = settings[8].Split(' ');
                    var readsLatitudeString   = readsLatitude[readsLatitude.Length - 1];
                    var readsLongtitude       = settings[9].Split(' ');
                    var readsLongtitudeString = readsLongtitude[readsLongtitude.Length - 1];
                    BasicGeoposition location = new BasicGeoposition();
                    location.Latitude  = double.Parse(readsLatitudeString, System.Globalization.CultureInfo.InvariantCulture);
                    location.Longitude = double.Parse(readsLongtitudeString, System.Globalization.CultureInfo.InvariantCulture);
                    Geopoint pointOfPosition = new Geopoint(location);


                    MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(pointOfPosition);

                    if (result.Status == MapLocationFinderStatus.Success && result.Locations.Count > 0)
                    {
                        System.Diagnostics.Debug.Write(" line 88" + Globals._email);
                    }
                    else
                    {
                        errormessage.Text = "Not Found";
                        // tbOutputText.Text = "No results";
                        System.Diagnostics.Debug.Write(" No results");
                    }
                }
            }

            catch (Exception ex)
            {
                if (ex.HResult.ToString("X") == "80072EE7")
                {
                    errormessage.Text = "Error: " + " Message: check your internet connection";
                }
                else
                {
                    errormessage.Text = "Error: " + ex.Message;
                }
            }
        }
Ejemplo n.º 13
0
        private async void InitializeMap()
        {
            var queryHintGeoPosition = new BasicGeoposition
            {
                Latitude  = 47.643,
                Longitude = -122.131
            };
            var result =
                await
                MapLocationFinder.FindLocationsAsync(App.EventModel.EventAddress, new Geopoint(queryHintGeoPosition));

            if (result != null && result.Locations.Count != 0)
            {
                await mapControl.TrySetViewAsync(result.Locations[0].Point, 16, 0, 0, MapAnimationKind.None);
            }

            var mapIconStreamReference =
                RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/mappin.png"));
            var mapIcon = new MapIcon
            {
                Location = mapControl.Center,
                NormalizedAnchorPoint = new Point(0.5, 1.0),
                Title  = "Event location",
                Image  = mapIconStreamReference,
                ZIndex = 0
            };

            mapControl.MapElements.Add(mapIcon);
        }
Ejemplo n.º 14
0
        public async Task <bool> MoveMap(string location, string type = "")
        {
            var mapLocations = await MapLocationFinder.FindLocationsAsync(location, null);

            double zoomLevel;

            switch (type)
            {
            case "city":
                zoomLevel = 10;
                break;

            case "continent":
                zoomLevel = 4;
                break;

            case "country":
                zoomLevel = 6;
                break;

            case "us_state":
                zoomLevel = 7;
                break;

            default:
                zoomLevel = 4;
                break;
            }

            return(await Map.TrySetViewAsync(mapLocations.Locations.First().Point, zoomLevel).AsTask());
        }
Ejemplo n.º 15
0
        private static async Task <string> DoGetLocation()
        {
            string town = null;

            try
            {
                MapService.ServiceToken = "sTHkEbHCyiH_iqm85_CC9A";
                Geolocator geolocator = new Geolocator();
                geolocator.DesiredAccuracyInMeters = 1500;
                Geoposition pos = await geolocator.GetGeopositionAsync(TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(1));

                BasicGeoposition basicpos = new BasicGeoposition();
                basicpos.Latitude  = pos.Coordinate.Point.Position.Latitude;
                basicpos.Longitude = pos.Coordinate.Point.Position.Longitude;;
                Geopoint point = new Geopoint(basicpos);

                MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(point);

                try { town = result.Locations[0].Address.Town; }
                catch (ArgumentOutOfRangeException) { town = null; }
            }
            catch (Exception) { return(null); }

            return(town);
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            MapService.ServiceToken = "w0Liy8GfWh7QJ0Vf3oKS~eZWPKcr32Kuierg9o3MALA~ApX3gsxp_26GUpHCfebArqPRcl60jH-CA1xilc9CtbTivIOTJsb7UiWUfQPzWPrc";
            var geolocator = new Geolocator();
            var position   = await geolocator.GetGeopositionAsync();

            SetLocationMap.Center    = position.Coordinate.Point;
            SetLocationMap.ZoomLevel = 19;

            var mapLocation = await MapLocationFinder.FindLocationsAtAsync(position.Coordinate.Point);

            if (mapLocation.Status == MapLocationFinderStatus.Success)
            {
                address = mapLocation.Locations[0].Address.StreetNumber + " " + mapLocation.Locations[0].Address.Street + ", " + mapLocation.Locations[0].Address.Town + ", " + mapLocation.Locations[0].Address.Country;
                MapIcon mapPin = new MapIcon();
                mapPin.Image    = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Images/MapPin.png"));
                mapPin.Location = position.Coordinate.Point;
                mapPin.Title    = address;
                SetLocationMap.MapElements.Clear();
                SetLocationMap.MapElements.Add(mapPin);
                MapAddress.Text = address;
            }
            else
            {
                //dialog.Content = "Not Found";
            }
        }
Ejemplo n.º 17
0
        private async void geolocator_StatusChanged(Geolocator sender, StatusChangedEventArgs args)
        {
            string status = "";

            switch (args.Status)
            {
            case PositionStatus.Disabled: status = "GPS Disabled"; break;

            case PositionStatus.Initializing: status = "Initializing"; break;

            case PositionStatus.Ready:
                status = "GPS is ready";
                try
                {
                    var position = await locator.GetGeopositionAsync();

                    BasicGeoposition myLocation;
                    myLocation = new BasicGeoposition
                    {
                        Longitude = position.Coordinate.Longitude,
                        Latitude  = position.Coordinate.Latitude
                    };

                    await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        MainPage.MyLongitude = position.Coordinate.Longitude.ToString();
                        MainPage.MyLatitude  = position.Coordinate.Latitude.ToString();
                    });

                    Geopoint pointToReverseGeocode = new Geopoint(myLocation);
                    MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

                    await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                    {
                        MainPage.MyWilaya  = result.Locations[0].Address.Region;
                        MainPage.MyCountry = result.Locations[0].Address.Country;
                        MainPage.MyCommune = result.Locations[0].Address.Town;
                        submit.IsEnabled   = true;

                        /* golo.Text = "Latitude " + MainPage.MyLatitude +
                         *    "Longitude " + MainPage.MyLongitude +
                         *    "Country " + MainPage.MyCountry +
                         *    "Commune " + MainPage.MyCommune +
                         *    "Wilaya  " + MainPage.MyWilaya;*/
                    });
                }
                catch (Exception exx)
                {
                    var dialoger = new MessageDialog("Something went wrong, try again!");
                    await dialoger.ShowAsync();
                }
                break;

            case PositionStatus.NotAvailable:
            case PositionStatus.NotInitialized:
            case PositionStatus.NoData:
                break;
            }
            await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { header.Text = status; });
        }
Ejemplo n.º 18
0
        private async void btnBrowse_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                BeginLoadingIcon();

                string addressToGeocode = txtAddress.Text;

                // The nearby location to use as a query hint.
                BasicGeoposition queryHint = new BasicGeoposition();
                queryHint.Latitude  = 47.643;
                queryHint.Longitude = -122.131;
                Geopoint hintPoint = new Geopoint(queryHint);

                MapLocationFinderResult result =
                    await MapLocationFinder.FindLocationsAsync(
                        addressToGeocode,
                        hintPoint,
                        3);

                if (result.Status == MapLocationFinderStatus.Success)
                {
                    mLastLat  = result.Locations[0].Point.Position.Latitude;
                    mLastLong = result.Locations[0].Point.Position.Longitude;
                    CenterMap(mLastLat, mLastLong, 17);
                }

                EndLoadingIcon();
            }
            catch (Exception)
            {
                EndLoadingIcon();
                DialogBox.ShowOk("Error", "Communication error with Azure server, please try again.");
            }
        }
Ejemplo n.º 19
0
        //private async void Button_Click(object sender, RoutedEventArgs e)
        //{
        //    var pos = await LocationManager.GetLocation();

        //    var lat = pos.Coordinate.Latitude;
        //    var lon = pos.Coordinate.Latitude;


        //    var weather = await WeatherProxyMap.GetWeather(lat, lon);

        //    WeatherCondition.Text = ((int)weather.main.temp).ToString() + " " + weather.name;
        //}

        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            //Show Weather
            var citySearch = CitySearch.Text;

            var weather = await WeatherProxyMapByCity.GetWeather(citySearch);

            CityNameTxtBlock.Text = ((int)weather.main.temp).ToString() + " " + weather.name;

            //Show on map
            var address = citySearch;

            var results = await MapLocationFinder.FindLocationsAsync(address, null);

            if (results.Status == MapLocationFinderStatus.Success)
            {
                var lat = results.Locations[0].Point.Position.Latitude;
                var lon = results.Locations[0].Point.Position.Longitude;

                var center = new Geopoint(new BasicGeoposition()
                {
                    Latitude  = lat,
                    Longitude = lon
                });

                await MyMap.TrySetSceneAsync(MapScene.CreateFromLocationAndRadius(center, 3000));
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Geolokalizacja podanego adresu (adres -> współ. geograf.).
        /// </summary>
        private async void Szukaj_Click(object sender, RoutedEventArgs e)
        {
            MapLocationFinderResult wynik = await MapLocationFinder.FindLocationsAsync(txAdres.Text, new Geopoint(DaneGeograficzne.pktStartowy), 3);

            if (txAdres.Text.Length > 0)
            {
                tbBlad.Text = "";
                if (wynik.Status == MapLocationFinderStatus.Success)
                {
                    DaneGeograficzne.pktDocelowy = wynik.Locations[0].Point.Position;
                    DaneGeograficzne.opisCelu    = txAdres.Text;
                    tbDlg.Text  = wynik.Locations[0].Point.Position.Longitude.ToString();
                    tbSzer.Text = wynik.Locations[0].Point.Position.Latitude.ToString();
                }
                else
                {
                    tbBlad.Text = "Adres jest nieprawidłowy!";
                }
            }
            else
            {
                tbBlad.Text = "Adres jest nieprawidłowy!";
                tbDlg.Text  = "";
                tbSzer.Text = "";
            }
        }
Ejemplo n.º 21
0
        // Afficher les informations de l'evenement concerné
        public async void EventPinTapped(object sender, TappedRoutedEventArgs e)
        {
            Image    image    = e.OriginalSource as Image;
            int      eventId  = Convert.ToInt32(image.Name);
            EventGet eventGet = await this._apiService.GetEventByIdAsync(eventId);

            Geopoint position = new Geopoint(new BasicGeoposition()
            {
                Latitude  = eventGet.Address.Latitude,
                Longitude = eventGet.Address.Longitude
            });

            MapLocationFinderResult finderResult = await MapLocationFinder.FindLocationsAtAsync(position);

            string address = string.Empty;

            if (finderResult.Status == MapLocationFinderStatus.Success)
            {
                var selectedLocation = finderResult.Locations.First();
                address = String.Format("{0} {1} ; {2} ", selectedLocation.Address.StreetNumber, selectedLocation.Address.Street,
                                        selectedLocation.Address.Town);
            }
            if (this._popup != null)
            {
                this._popup.IsOpen = false;
            }
            this._popup        = this.GeneratePopup(eventGet, address);
            this._popup.IsOpen = true;
        }
Ejemplo n.º 22
0
        public async void dajLokaciju()
        {
            Geoposition pos          = null;
            var         accessStatus = await Geolocator.RequestAccessAsync();

            if (accessStatus == GeolocationAccessStatus.Allowed)
            {
                Geolocator geolocator = new Geolocator {
                    DesiredAccuracyInMeters = 10
                };
                pos = await geolocator.GetGeopositionAsync();
            }

            TrenutnaLokacija = pos.Coordinate.Point;
            Latitude         = (TrenutnaLokacija.Position.Latitude).ToString();
            Longitude        = (TrenutnaLokacija.Position.Longitude).ToString();

            MapLocationFinderResult result = await
                                             MapLocationFinder.FindLocationsAtAsync(pos.Coordinate.Point);

            if (result.Status == MapLocationFinderStatus.Success)
            {
                Adresa = result.Locations[0].Address.Street;
            }

            Cryptzone     = (GetDistanceInKm(SveAtrakcije[0].Latitude, SveAtrakcije[0].Longitude, Convert.ToDouble(Latitude), Convert.ToDouble(Longitude))).ToString();
            Dreamville    = (GetDistanceInKm(SveAtrakcije[1].Latitude, SveAtrakcije[1].Longitude, Convert.ToDouble(Latitude), Convert.ToDouble(Longitude))).ToString();
            FunDome       = (GetDistanceInKm(SveAtrakcije[2].Latitude, SveAtrakcije[2].Longitude, Convert.ToDouble(Latitude), Convert.ToDouble(Longitude))).ToString();
            Phantomtown   = (GetDistanceInKm(SveAtrakcije[3].Latitude, SveAtrakcije[3].Longitude, Convert.ToDouble(Latitude), Convert.ToDouble(Longitude))).ToString();
            Shockland     = (GetDistanceInKm(SveAtrakcije[4].Latitude, SveAtrakcije[4].Longitude, Convert.ToDouble(Latitude), Convert.ToDouble(Longitude))).ToString();
            GhostParadise = (GetDistanceInKm(SveAtrakcije[5].Latitude, SveAtrakcije[5].Longitude, Convert.ToDouble(Latitude), Convert.ToDouble(Longitude))).ToString();
            Evertown      = (GetDistanceInKm(SveAtrakcije[6].Latitude, SveAtrakcije[6].Longitude, Convert.ToDouble(Latitude), Convert.ToDouble(Longitude))).ToString();
            PlayRealm     = (GetDistanceInKm(SveAtrakcije[7].Latitude, SveAtrakcije[7].Longitude, Convert.ToDouble(Latitude), Convert.ToDouble(Longitude))).ToString();
        }
Ejemplo n.º 23
0
        private async Task <MapLocationFinderResult> GetAddressFromCoordinatesAsync(double Lat, double Lon)
        {
            JObject obj;

            try
            {
                StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(@"ms-appx:///Resources/BingMapsKey.txt"));

                var lines = await FileIO.ReadTextAsync(file);

                obj = JObject.Parse(lines);
            }
            catch (Exception)
            {
                return(null);
            }
            MapService.ServiceToken = (string)obj.SelectToken("key");

            BasicGeoposition location = new BasicGeoposition();

            location.Latitude  = Lat;
            location.Longitude = Lon;
            Geopoint pointToReverseGeocode = new Geopoint(location);

            // Reverse geocode the specified geographic location.
            return(await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode));

            // If the query returns results, display the name of the town
            // contained in the address of the first result.
        }
        public static async Task <string> GetCityName()
        {
            AdmConfigBuilder configBuilder = AdmConfigBuilder.Instance();

            Geopoint geopoint = new(new BasicGeoposition
            {
                Latitude = configBuilder.LocationData.Lat,
                Longitude = configBuilder.LocationData.Lon
            });

            try
            {
                MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(geopoint, MapLocationDesiredAccuracy.Low);

                if (result.Status == MapLocationFinderStatus.Success)
                {
                    return(result.Locations[0].Address.Town);
                }
                else
                {
                    return(null);
                }
            }
            catch (SEHException)
            {
                return(string.Format("(~{0,00}, ~{1,00})", geopoint.Position.Latitude, geopoint.Position.Longitude));
            }
        }
Ejemplo n.º 25
0
        private async void UpdateLocationExecute()
        {
            var location = await _locationService.GetPositionAsync();

            if (location == null)
            {
                var confirm = await MessagePopup.ShowAsync(Strings.Resources.GpsDisabledAlert, Strings.Resources.AppName, Strings.Resources.ConnectingToProxyEnable, Strings.Resources.Cancel);

                if (confirm == ContentDialogResult.Primary)
                {
                    await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location"));
                }

                return;
            }

            var geopoint = new Geopoint(new BasicGeoposition {
                Latitude = location.Latitude, Longitude = location.Longitude
            });

            Location = location;
            Settings.Appearance.UpdateNightMode();

            var result = await MapLocationFinder.FindLocationsAtAsync(geopoint, MapLocationDesiredAccuracy.Low);

            if (result.Status == MapLocationFinderStatus.Success)
            {
                Town = result.Locations[0].Address.Town;
            }
        }
Ejemplo n.º 26
0
        public static async Task <LocationHelper> GetCity(List <City> cities)
        {
            var returnVal = new LocationHelper();


            try
            {
                var geolocator = new Geolocator();
                geolocator.DesiredAccuracyInMeters = 100;
                Geoposition position = await geolocator.GetGeopositionAsync();

                // reverse geocoding
                BasicGeoposition myLocation = new BasicGeoposition
                {
                    Longitude = position.Coordinate.Longitude,
                    Latitude  = position.Coordinate.Latitude
                };

                Geopoint pointToReverseGeocode = new Geopoint(myLocation);

                Dictionary <string, double> cityDistances = new Dictionary <string, double>();
                foreach (var city in cities)
                {
                    if (city.Location != null && city.Location.Longitude != null && city.Location.Latitude != null)
                    {
                        var distance = DistanceTo(myLocation.Latitude, myLocation.Longitude, city.Location.Latitude.Value,
                                                  city.Location.Longitude.Value);

                        cityDistances.Add(city.CityName, Math.Abs(distance));
                    }
                }

                if (cityDistances.Count > 0)
                {
                    var shortest = cityDistances.Aggregate((c, d) => c.Value < d.Value ? c : d);
                    returnVal.FoundCity = shortest.Key;
                }
                else
                {
                    returnVal.FoundCity = "";
                }


                returnVal.UserLocation = new GeoCodeItem()
                {
                    Longitude = myLocation.Longitude,
                    Latitude  = myLocation.Latitude
                };

                MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

                returnVal.FoundTown = result.Locations[0].Address.Town;
            }
            catch (Exception)
            {
            }

            // here also it should be checked if there result isn't null and what to do in such a case
            return(returnVal);
        }
        /// <summary>
        /// Retrieve positions for address.
        /// </summary>
        /// <param name="address">Desired address</param>
        /// <param name="mapKey">Map Key required only on UWP</param>
        /// <returns>Positions of the desired address</returns>
        public async Task <IEnumerable <Position> > GetPositionsForAddressAsync(string address, string mapKey = null)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            SetMapKey(mapKey);

            var queryResults = await MapLocationFinder.FindLocationsAsync(address, null, 10);

            var positions = new List <Position>();

            if (queryResults?.Locations == null)
            {
                return(positions);
            }

            foreach (var p in queryResults.Locations)
            {
                positions.Add(new Position
                {
                    Latitude  = p.Point.Position.Latitude,
                    Longitude = p.Point.Position.Longitude
                });
            }

            return(positions);
        }
Ejemplo n.º 28
0
        private async void getDetail(Geoposition pos)
        {
            //locator setup
            BasicGeoposition location = new BasicGeoposition();

            location.Latitude  = pos.Coordinate.Latitude;
            location.Longitude = pos.Coordinate.Longitude;
            Geopoint pointToReverseGeocode = new Geopoint(location);

            //return result of map location query
            MapLocationFinderResult result =
                await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

            if (result.Status == MapLocationFinderStatus.Success)
            {
                //simply getting whatever we need from locator
                tblLocation2.Text += "Country:    " + result.Locations[0].Address.Country.ToString() + System.Environment.NewLine +
                                     "City:    " + result.Locations[0].Address.Town.ToString() + System.Environment.NewLine +
                                     "District:  " + result.Locations[0].Address.District.ToString() + System.Environment.NewLine +
                                     "Street:  " + result.Locations[0].Address.Street.ToString() + System.Environment.NewLine +

                                     "Time:    " + pos.Coordinate.Timestamp.ToString() + System.Environment.NewLine +
                                     "Longitude: " + pos.Coordinate.Latitude.ToString() + System.Environment.NewLine +
                                     "Latitude:  " + pos.Coordinate.Longitude.ToString() + System.Environment.NewLine + System.Environment.NewLine +
                                     "Formatted Address:  " + result.Locations[0].Address.FormattedAddress.ToString();
            }
        }
Ejemplo n.º 29
0
        // Metoda koja određuje trenutnu lokaciju i postavlja vrijednosti u odgovarajuće textboxove
        public async void getLocationData(object obj)
        {
            // Da li se smije uzeti lokacija, trazi se odobrenje od korisnika (takodjer treba i capability)
            var accessStatus = await Geolocator.RequestAccessAsync();

            if (accessStatus == GeolocationAccessStatus.Allowed)
            {
                // Uzimanje pozicije ako smije
                Geolocator geolocator = new Geolocator {
                    DesiredAccuracyInMeters = 10
                };
                Geoposition pos = await geolocator.GetGeopositionAsync();

                // Uzimamo lokaciju
                CurrentLocation = pos.Coordinate.Point;

                // Uzimamo podatke o drzavi, gradu i adresi
                MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(pos.Coordinate.Point);

                // Koje podatke nađe, ispiše u textboxove
                if (result.Status == MapLocationFinderStatus.Success)
                {
                    Country = result.Locations[0].Address.Country;
                    City    = result.Locations[0].Address.Town;
                    Address = result.Locations[0].Address.Street;
                }
            }
            else
            {
                var dialog = new MessageDialog("Niste omogućili da aplikacija koristi vašu lokaciju.");
                await dialog.ShowAsync();
            }
        }
Ejemplo n.º 30
0
        public static async Task <string> GetCityAsync()
        {
            string city       = "Pretoria";
            string BingMapKey = "pffgd1QKrnfEoKF7ZS8b~KkG1SyHPGXx7IX0AdNl2yQ~AiOt6YNLRHeRi4QkE8ySU2gTqhE9Mba-j_CciBaHgetWcXXUJhThcsMYl2ZIyqF4";

            MapService.ServiceToken = BingMapKey;

            //Get City coordinates from Bing Maps
            BasicGeoposition usercoordinates = new BasicGeoposition();

            //Get Location in latitude and longitude
            var position = await GetPosition();

            //convert them to city name

            usercoordinates.Latitude  = position.Coordinate.Point.Position.Latitude;
            usercoordinates.Longitude = position.Coordinate.Point.Position.Longitude;
            Geopoint geopoint = new Geopoint(usercoordinates);


            // Reverse geocode the specified geographic location.


            MapLocationFinderResult result =
                await MapLocationFinder.FindLocationsAtAsync(geopoint);


            city = result.Locations[0].Address.District;
            city = city.Replace(" ", "_");


            return(city);
        }