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";
            }
        }
Exemplo n.º 2
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;
                }
            }
        }
Exemplo n.º 3
0
        // http://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn631249.aspx
        public async Task <List <Portable.Model.GeocodeResult> > ExecuteQuery(string query)
        {
            throw new NotImplementedException("Not yet fully implemented, testing only");

            try
            {
                // TODO: center for Austria (lat, lon), hint Austria in search string
                BasicGeoposition queryHint = new BasicGeoposition();
                queryHint.Latitude  = 47.643;
                queryHint.Longitude = -122.131;
                Geopoint hintPoint = new Geopoint(queryHint);

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

                if (result.Status == MapLocationFinderStatus.Success)
                {
                    return(result.Locations.Select(l => new Portable.Model.GeocodeResult()
                    {
                        Latitude = l.Point.Position.Latitude,
                        Longitude = l.Point.Position.Longitude,
                        Name = l.DisplayName,
                    }).ToList());
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
            }

            return(new List <GeocodeResult>());
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        private async void GetGpsLocation()
        {
            // Get the location
            try
            {
                // Get the point
                Geolocator m_geoLocator = new Geolocator();
                await Geolocator.RequestAccessAsync();

                Geoposition position = await m_geoLocator.GetGeopositionAsync();

                // Get the address
                MapLocationFinderResult mapLocationFinderResult = await MapLocationFinder.FindLocationsAtAsync(position.Coordinate.Point);

                if (mapLocationFinderResult.Status != MapLocationFinderStatus.Success)
                {
                    throw new Exception();
                }

                WeatherSettings.Location loc = new WeatherSettings.Location
                {
                    City  = mapLocationFinderResult.Locations[0].Address.Town,
                    State = mapLocationFinderResult.Locations[0].Address.Region
                };
                m_settings.CurrentLocation = loc;
                ui_locationText.Text       = "Your Location: " + mapLocationFinderResult.Locations[0].Address.Town;

                // Send the location to the pie
                await SendNewSettings(m_settings);
            }
            catch (Exception)
            {
                ui_locationText.Text = "Failed to get your location!";
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Converts the specified address to a geographic location
        /// </summary>
        /// <param name="address">The address to geocode</param>
        /// <returns>Location of the address as Geopoint</returns>
        private async Task <Geopoint> Geocode(string address)
        {
            // Nearby location to use as a query hint.
            BasicGeoposition queryHint = new BasicGeoposition();

            queryHint.Latitude  = 48.1333;
            queryHint.Longitude = 11.5667;
            Geopoint hintPoint = new Geopoint(queryHint);

            // Geocode the specified address, using the specified reference point
            // as a query hint. Return no more than 3 results.
            MapLocationFinderResult result =
                await MapLocationFinder.FindLocationsAsync(
                    address,
                    hintPoint,
                    3);

            // If the query returns results, display the coordinates
            // of the first result.
            if (result.Status == MapLocationFinderStatus.Success)
            {
                var output = "result = (" +
                             result.Locations[0].Point.Position.Latitude.ToString() + "," +
                             result.Locations[0].Point.Position.Longitude.ToString() + ")";
                Debug.Write(output);
                BasicGeoposition point = new BasicGeoposition();
                point.Latitude  = result.Locations[0].Point.Position.Latitude;
                point.Longitude = result.Locations[0].Point.Position.Longitude;
                return(new Geopoint(point));
            }
            return(null);
        }
        private async void getLocation(Geoposition pos)
        {
            //locator setup
            BasicGeoposition location = new BasicGeoposition();

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


            // myPositions is a query to find exact location. in this case it will show the location of the device settings.
            MapLocationFinderResult myPosition = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);


            //if position found then print information to the screen
            if (myPosition.Status == MapLocationFinderStatus.Success)
            {
                tblLocation2.Text += "Country:    " + myPosition.Locations[0].Address.Country.ToString()
                                     + System.Environment.NewLine +
                                     "City:    " + myPosition.Locations[0].Address.Town.ToString()
                                     + System.Environment.NewLine +
                                     "Address:  " + myPosition.Locations[0].Address.FormattedAddress.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;
            }
        }
Exemplo n.º 8
0
        private async Task <IReadOnlyList <MapLocation> > GetCoordinateForNameAsync(string searchText)
        {
            IAsyncOperation <MapLocationFinderResult> finderTask = null;

            try
            {
                Debug.WriteLine("Started gettin place coordinate");

                finderTask = MapLocationFinder.FindLocationsAsync(searchText, MapControl.Center);

                MapLocationFinderResult result = await finderTask;


                if (result.Status == MapLocationFinderStatus.Success && result.Locations.Count > 0)
                {
                    return(result.Locations);
                }

                return(null);
            }
            finally
            {
                if (finderTask != null)
                {
                    if (finderTask.Status == AsyncStatus.Started)
                    {
                        Debug.WriteLine("Attempting to cancel place coordinate task");
                        finderTask.Cancel();
                    }

                    finderTask.Close();
                }
            }
        }
        private async void txtToLocation_LostFocus(object sender, RoutedEventArgs e)
        {
            point = (await(new Geolocator()).GetGeopositionAsync()).Coordinate.Point;
            MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(txtToLocation.Text, point);

            await myMap.TrySetViewAsync(result.Locations[0].Point, 10);
        }
Exemplo n.º 10
0
        private async void UIElement_OnKeyDown(object sender, KeyRoutedEventArgs e)
        {
            if (e.Key != VirtualKey.Enter)
            {
                return;
            }
            e.Handled = true;

            var textBox = (TextBox)sender;
            MapLocationFinderResult mapLocationFinderResult = await _viewModel.FindLocation(textBox.Text);

            MapControl.MapElements.Clear();
            if (mapLocationFinderResult.Status != MapLocationFinderStatus.Success)
            {
                return;
            }
            if (mapLocationFinderResult.Locations.Count <= 0)
            {
                return;
            }
            MapLocation mapLocation = mapLocationFinderResult.Locations[0];
            var         mapIcon     = new MapIcon
            {
                Location = mapLocation.Point,
                Title    = mapLocation.DisplayName,
            };

            MapControl.MapElements.Add(mapIcon);
            await MapControl.TrySetViewAsync(mapLocation.Point);
        }
Exemplo n.º 11
0
        private async Task <Geopoint> geocodeDireccion(String addressToGeocode)
        {
            // Se busca la dirección o lugar específicado, se establece un punto cercano como referencia (en este caso la ubicación inicial del usuario al ejecutar la App)
            MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(
                addressToGeocode,
                miPosiciónActual,
                3);

            //Si el resultado obtenido ha sido correcto, y si el array de localizaciones es mayor que 0
            if (result.Status == MapLocationFinderStatus.Success)
            {
                if (result.Locations.Count > 0)
                {
                    Debug.WriteLine("result = (" + result.Locations[0].Point.Position.Latitude.ToString() + "," + result.Locations[0].Point.Position.Longitude.ToString() + ")");
                }
                else
                {
                    Debug.WriteLine("No ha encontrado nada el Geocode");
                }
            }

            Geopoint valor_retorno = result.Locations[0].Point;

            return(valor_retorno);
        }
Exemplo n.º 12
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;
            }
        }
        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());
            }
        }
Exemplo n.º 14
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();
            }
        }
Exemplo n.º 15
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"));
            }
        }
Exemplo n.º 16
0
        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";
            }
        }
Exemplo n.º 17
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);
            });
        }
Exemplo n.º 18
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;
        }
        private async void searchLocation_Click(object sender, RoutedEventArgs e)
        {
            if (!location.Text.Equals(null) && !location.Text.Equals(""))
            {
                searchingWait.IsActive = true;
                App.searchParam.addToSearchHistory(location.Text);
                MapLocationFinderResult result = await App.searchParam.getLocDataFromCity(location.Text);

                if (result.Status == MapLocationFinderStatus.Success)
                {
                    if (!App.searchParam.getBasicSearchResults().Any())
                    {
                        errorSymbol.Text       = "\xE783";
                        errorMsg.Text          = "We did not find any listings.";
                        searchingWait.IsActive = false;
                    }
                    else
                    {
                        this.Frame.Navigate(typeof(intro));
                    }
                }
                else
                {
                    errorSymbol.Text = "\xE783";
                    errorMsg.Text    = "We couldn't find your location.";
                }
            }
            else
            {
                errorSymbol.Text = "\xE783";
                errorMsg.Text    = "Please enter a valid location";
            }
        }
Exemplo n.º 20
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; });
        }
Exemplo n.º 21
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();
            }
        }
Exemplo n.º 22
0
        private static async Task <string> DoGetLocation()
        {
            var accessStatus = await Geolocator.RequestAccessAsync();

            string town = null;

            if (accessStatus == GeolocationAccessStatus.Allowed)
            {
                try
                {
                    MapService.ServiceToken = "lxJiVzjPvY4QkfSEgGkJ~N1FxApXmFRQDiReZBeDlfg~AsJ7th7S8_VQhANRLPT4G0IJCk-T_sUZzRgcRFzl5XjkYrEOvJg5jwUpdXv75xEA";
                    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);

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

            return(town);
        }
        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));
            }
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
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();
        }
Exemplo n.º 26
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 = "";
            }
        }
Exemplo n.º 27
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.");
            }
        }
        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));
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
0
        private async Task <string> GetCurrentCity()
        {
            var location = await Settings.GetFavoriteLocation();

            if (UseGPSLocation(location))
            {
                Geopoint pointToReverseGeocode = new Geopoint(_lastPosition);

                // Reverse geocode the specified geographic location.
                MapLocationFinderResult result =
                    await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

                // If the query returns results, display the name of the town
                // contained in the address of the first result.
                if (result.Status != MapLocationFinderStatus.Success || result.Locations.Count == 0)
                {
                    return(null);
                }

                return(result.Locations[0].Address.Town);
            }

            return(location.Town);
            //TownTextBlock.Text = location.Town;
        }
Exemplo n.º 31
0
        private async void SearchAddress(CancellationToken token)
        {
            if (string.IsNullOrWhiteSpace(SearchTextBox.Text))
                return;

            VisualStateManager.GoToState(this, "Searching", true);
            if (token.IsCancellationRequested)
            {
                return;
            }
            SearchingProgressBar.Visibility = Visibility.Visible;

            var task = FindLocation(SearchTextBox.Text, userLastLocation, 1);
            if (task != await Task.WhenAny(task, Task.Delay(3000, token)))
            {
                // timout case 
                Debug.WriteLine("searching address TIMEOUT or CANCELED !");
                if (!token.IsCancellationRequested)
                    SearchAddress(token);
                return;
            }

            if (token.IsCancellationRequested)
            {
                return;
            }
            var result = task.Result;


            // If the query returns results, display the coordinates
            // of the first result.
            if (result.Status == MapLocationFinderStatus.Success && result.Locations.Count > 0)
            {
                StopCompassAndUserLocationTracking();



                lastSearchLocationResult = result;
                MapCtrl.Center = result.Locations.FirstOrDefault().Point;
                MapCtrl.Heading = 0;
                SearchLocationText.Text = result.ParseMapLocationFinderResultAddress();
                ShowSearchLocationPoint(result.Locations.FirstOrDefault().Point, SearchLocationText.Text);
                HideSearch();


            }
            else
            {
                if (!token.IsCancellationRequested)
                {
                    VisualStateManager.GoToState(this, "SearchVisible", true);
                    SearchStatusTextBlock.Text = "Couldn't find that place. Try using different spelling or keywords.";
                }
            }
        }