Exemplo n.º 1
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());
        }
        /// <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);
        }
Exemplo n.º 3
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.º 4
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);
        }
Exemplo n.º 5
0
        public async void  getLocationAddress()
        {
            Geolocator  geolocator      = new Geolocator();
            Geoposition currentPosition = await geolocator.GetGeopositionAsync();

            string address = "pretoria";
            MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(
                address, currentPosition.Coordinate.Point, 5);

            if (result.Status == MapLocationFinderStatus.Success)
            {
                List <string> locations = new List <string>();
                foreach (MapLocation mapLocation in result.Locations)
                {
                    // create a display string of the map location
                    string display = mapLocation.Address.StreetNumber + " " +
                                     mapLocation.Address.Street + Environment.NewLine +
                                     mapLocation.Address.Town + ", " +
                                     mapLocation.Address.RegionCode + "  " +
                                     mapLocation.Address.PostCode + Environment.NewLine +
                                     mapLocation.Address.CountryCode;
                    // Add the display string to the location list.
                    locations.Add(display);
                    address = display;
                    lstView.Items.Add("location          " + display);
                }
            }
        }
        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.º 7
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();
                }
            }
        }
        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";
            }
        }
        private async void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
        {
            string city = args.ChosenSuggestion as string ?? args.QueryText;

            if (!string.IsNullOrEmpty(city))
            {
                var data = await m_aqiManager.GetBreezometerAirQualityIndexByLocationAsync(city);

                if (!data?.DataValid ?? true)
                {
                    MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(city, new Geopoint(new BasicGeoposition()));

                    var location = result.Locations.FirstOrDefault();

                    if (location != null)
                    {
                        var pos = location.Point.Position;
                        data = await m_aqiManager.GetBreezometerAirQualityIndexAsync(pos.Latitude, pos.Longitude);
                    }

                    if (!data?.DataValid ?? true)
                    {
                        await AppNavServiceManager.ShowPopup("No data found for this city!");
                    }
                }
                else
                {
                    // TODO: ... TODO....
                    await AppNavServiceManager.ShowPopup("Data found!");

                    //MapControl.
                }
            }
        }
Exemplo n.º 10
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));
            }
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
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.º 13
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);
            }
        }
Exemplo n.º 14
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.");
            }
        }
Exemplo n.º 15
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";
            }
        }
Exemplo n.º 16
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.º 17
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);
        }
Exemplo n.º 18
0
        private void GenerateActions()
        {
            ProfileCommands = new ObservableCollection <ProfileCommand>();

            //Mise en place des champs de commande
            //Commande pour appeler
            if (!_userModel.numeroPortable.Equals(""))
            {
                Action command;
                //Si on peut appeler
                if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.Calls.CallsPhoneContract", 1, 0))
                {
                    command = new Action(() =>
                    {
                        PhoneCallManager.ShowPhoneCallUI(_userModel.numeroPortable, Username);
                    });
                }
                //Si le device ne peut passer d'appel
                else
                {
                    command = new Action(async() =>
                    {
                        string errMsg        = "Désolé, les appels ne sont pas disponnibles sur votre appareil";
                        MessageDialog dialog = new MessageDialog(errMsg);
                        await dialog.ShowAsync();
                    });
                }
                ProfileCommands.Add(new ProfileCommand("Appeler", _userModel.numeroPortable, command));
            }
            //Commande pour naviguer vers
            if (!_userModel.adresse.Equals(""))
            {
                Action command = new Action(async() =>
                {
                    var locFinderResult = await MapLocationFinder.FindLocationsAsync(_userModel.adresse, new Geopoint(new BasicGeoposition()));

                    if (locFinderResult.Locations[0] == null)
                    {
                        string errMsg        = "Désolé, impossible de trouver où " + _userModel.prenom + " habite";
                        MessageDialog dialog = new MessageDialog(errMsg);
                        await dialog.ShowAsync();
                        return;
                    }

                    var geoPos = locFinderResult.Locations[0].Point.Position;

                    var driveToUri = new Uri(String.Format(
                                                 "ms-drive-to:?destination.latitude={0}&destination.longitude={1}&destination.name={2}",
                                                 geoPos.Latitude,
                                                 geoPos.Longitude,
                                                 _userModel.prenom + " " + _userModel.nom));

                    await Windows.System.Launcher.LaunchUriAsync(driveToUri);
                });

                ProfileCommands.Add(new ProfileCommand("Obtenir un itinéraire", _userModel.adresse, command));
                RaisePropertyChanged("ProfileCommands");
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// This method tries to find the geographical position of a given address.
        /// </summary>
        /// <param name="address">Address for which the geographical position should be found.</param>
        private async void FindAddress(string address)
        {
            try
            {
                // Getting current location of device
                Geoposition position;
                try
                {
                    App.ToggleProgressBar(true, ResourceLoader.GetForCurrentView().GetString("StatusBarGettingLocation"));
                    position = await ServiceLocator.Current.GetInstance <GeoHelper>().Locator.GetGeopositionAsync();

                    App.ToggleProgressBar(false, null);
                }
                catch (NullReferenceException nullEx)
                {
                    App.ToggleProgressBar(false, null);
                    return;
                }
                catch (Exception ex)
                {
                    App.ToggleProgressBar(false, null);

                    new MessageDialog(
                        ResourceLoader.GetForCurrentView().GetString("GPSError"),
                        ResourceLoader.GetForCurrentView().GetString("ErrorTitle")).ShowAsync();

                    return;
                }

                // Finding geographical position of a given address
                App.ToggleProgressBar(true, ResourceLoader.GetForCurrentView().GetString("StatusBarSearchingAddress"));
                MapLocationFinderResult FinderResult = await MapLocationFinder.FindLocationsAsync(address, position.Coordinate.Point);

                App.ToggleProgressBar(false, null);

                // Check, if any positions have been found
                if (FinderResult.Status == MapLocationFinderStatus.Success && FinderResult.Locations.Count > 0)
                {
                    // Center found location on the MapControl
                    Map.Center       = FinderResult.Locations.First().Point;
                    Map.DesiredPitch = 0;

                    await Map.TrySetViewAsync(FinderResult.Locations.First().Point, 15);
                }
                else
                {
                    await new MessageDialog(
                        ResourceLoader.GetForCurrentView().GetString("AddShopFindAddressDialogNotFoundText"),
                        ResourceLoader.GetForCurrentView().GetString("AddShopFindAddressDialogNotFoundTitle")).ShowAsync
                        ();
                }
            }
            catch (Exception ex)
            {
                new MessageDialog(
                    ResourceLoader.GetForCurrentView().GetString("GetLocationByAddressError"),
                    ResourceLoader.GetForCurrentView().GetString("ErrorTitle")).ShowAsync();
            }
        }
Exemplo n.º 20
0
        static async Task <IEnumerable <Location> > PlatformGetLocationsAsync(string address)
        {
            ValidateMapServiceToken();

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

            return(queryResults?.Locations?.ToLocations());
        }
Exemplo n.º 21
0
        public static async Task <IEnumerable <Location> > GetLocationsAsync(string address)
        {
            ValidateMapKey();

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

            return(queryResults?.Locations?.ToLocations());
        }
Exemplo n.º 22
0
        public void SearchTextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            // Only get results when it was a user typing,
            // otherwise assume the value got filled in by TextMemberPath
            // or the handler for SuggestionChosen.
            if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
            {
                //Set the ItemsSource to be your filtered dataset
                //sender.ItemsSource = dataset;
                var searchTerm = sender.Text;

                if (string.IsNullOrEmpty(searchTerm))
                {
                    // meaning we cleared the searchbox
                    DestinationRemoved();
                    return;
                }

                Dispatcher.DispatchAsync(async() =>
                {
                    try
                    {
                        var mapLocation = await MapLocationFinder.FindLocationsAsync(searchTerm, LocationPoint, 10);
                        //http://spatial.virtualearth.net/REST/v1/data/accessId/dataSourceName/entityTypeName(entityId)?$format=json&isStaging=isStaging&key=AuWKpDAtdfdkO_If4n1l1JWb-TMNZG3YUZAkpJJuz_bv86IEuxjUkLsq3TVhxZ3e

                        if (mapLocation.Status == MapLocationFinderStatus.Success)
                        {
                            Suggestions.Clear();
                            var results = mapLocation.Locations;
                            foreach (var result in results)
                            {
                                if (string.IsNullOrEmpty(result.Address.StreetNumber) || string.IsNullOrEmpty(result.Address.StreetNumber))
                                {
                                    Suggestions.Add(new AddressSearchResultViewModel()
                                    {
                                        Title = result.Address.FormattedAddress,
                                        Point = result.Point
                                    });
                                }
                                else
                                {
                                    Suggestions.Add(new AddressSearchResultViewModel()
                                    {
                                        Title    = $"{result.Address.StreetNumber} {result.Address.Street}",
                                        SubTitle = $"{result.Address.Town}, {result.Address.Region}",
                                        Point    = result.Point
                                    });
                                }
                            }
                        }
                    }
                    catch (ArgumentException)
                    {
                    }
                });
            }
        }
Exemplo n.º 23
0
        public async void Gettolocation(string address, Geopoint queryHintPoint)
        {
            var result = await MapLocationFinder.FindLocationsAsync(address, queryHintPoint);

            // Get the coordinates
            if (result.Status == MapLocationFinderStatus.Success)
            {
                double tolat  = result.Locations[0].Point.Position.Latitude;
                double tolong = result.Locations[0].Point.Position.Longitude;
            }
        }
Exemplo n.º 24
0
        static async Task <IEnumerable <Position> > GetPositionsForAddress(string address)
        {
            var queryResults = await MapLocationFinder.FindLocationsAsync(address, null, 10);

            var positions = new List <Position>();

            foreach (var result in queryResults?.Locations)
            {
                positions.Add(new Position(result.Point.Position.Latitude, result.Point.Position.Longitude));
            }
            return(positions);
        }
Exemplo n.º 25
0
        private async void txtLocation_LostFocus(object sender, RoutedEventArgs e)
        {
            btnGotoCurrentLocation.IsEnabled = false;
            btnGetCurrentLocation.IsEnabled  = false;

            MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(txtLocation.Text, point);

            await myMap.TrySetViewAsync(result.Locations[0].Point, mySlider.Value);

            btnGotoCurrentLocation.IsEnabled = true;
            btnGetCurrentLocation.IsEnabled  = true;
        }
        /// <summary>
        /// Get the latitude and longitude based on the trip's location.
        /// </summary>
        public async Task <List <double> > GetGeocode()
        {
            List <double>           geocoding = new List <double>();
            MapLocationFinderResult result    = await MapLocationFinder.FindLocationsAsync(TripLocation, null, 1);

            if (result.Status == MapLocationFinderStatus.Success)
            {
                geocoding.Add(result.Locations[0].Point.Position.Latitude);
                geocoding.Add(result.Locations[0].Point.Position.Longitude);
            }
            return(geocoding);
        }
Exemplo n.º 27
0
        public async Task <MapLocationFinderResult> findGeoLoc(string addressToGeocode)
        {
            // Geocode the specified address, using the specified reference point
            // as a query hint. Return no more than 3 results.
            var result = await MapLocationFinder.FindLocationsAsync(
                addressToGeocode,
                // Hint point.
                StaticTaqModel.twCenterLoc,
                3);

            return(result);
        }
Exemplo n.º 28
0
        private async void lsvCitas_ItemClick(object sender, ItemClickEventArgs e)
        {
            mapa.Routes.Remove(vistaRuta);

            var cita = e.ClickedItem as Cita;

            //Para mostrar una ruta, necesitamos el punto de inicio, que lo pondremos como el instituto
            BasicGeoposition bgInstituto = new BasicGeoposition()
            {
                Latitude = 37.373774,
                Longitude = -5.969034
            };
            Geopoint instituto = new Geopoint(bgInstituto);


            //Esto es una pista de dónde empezar a buscar la latitud y la longitud de la dirección del cliente
            BasicGeoposition pista = new BasicGeoposition();
            pista.Latitude = 40.416775;
            pista.Longitude = -3.703790;
            Geopoint madrid = new Geopoint(pista);

            //Nos devuelve las coordenadas
            MapLocationFinderResult result = await MapLocationFinder.FindLocationsAsync(cita.direccion, madrid);

            //Si encuentra la localización
            if (result.Status == MapLocationFinderStatus.Success)
            {
                //Esto es el BasicGeoposition con las coordenadas
                BasicGeoposition posicion = result.Locations[0].Point.Position;
                Geopoint centro = new Geopoint(posicion);

                //Intentamos buscar una ruta con coche del instituto a la dirección de destino
                MapRouteFinderResult ruta = await MapRouteFinder.GetDrivingRouteAsync(instituto, centro);
                if(ruta.Status == MapRouteFinderStatus.Success)
                {
                    //Si la encuentra, creamos la MapRouteView (que es lo que el MapControl acepta y se lo añadimos
                    vistaRuta = new MapRouteView(ruta.Route);
                    //También podemos cambiar el color de la línea de la ruta
                    vistaRuta.RouteColor = Colors.Red;
                    vistaRuta.OutlineColor = Colors.Black;

                    //Y se lo añadimos al MapControl
                    mapa.Routes.Add(vistaRuta);
                }
                
                //Ahora ponemos bien el mapa
                mapa.Center = centro;
                mapa.ZoomLevel = 17;
                
            }
            
        }
Exemplo n.º 29
0
        private async void SetMapCenter()
        {
            try
            {
                MapLocationFinderResult result =
                    await MapLocationFinder.FindLocationsAsync("13121 129th Ct NE, Kirkland, WA 98034", null);

                MapCenter = result.Locations.FirstOrDefault().Point;
            }
            catch
            {
            }
        }
Exemplo n.º 30
0
        public static async Task <MapLocationFinderResult> geocode(string location)
        {
            BasicGeoposition queryHint = new BasicGeoposition();
            var loc = await locator();

            queryHint.Latitude  = loc.Item1;
            queryHint.Longitude = loc.Item2;
            Geopoint hintPoint = new Geopoint(queryHint);

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

            return(result);
        }