Exemple #1
0
        public GeocodingLocation(Geopoint Location)
        {
            this.Location = Location;

            Name        = NameDefault;
            Description = DescriptionDefault;
            Status      = null;

            // Start the Geocoding request
            IAsyncOperation <MapLocationFinderResult> request = MapLocationFinder.FindLocationsAtAsync(Location);

            // Get notified when it is ready
            request.Completed = GeocodingCompleted;
        }
        //return true if successeded
        public async static Task <bool> GetCoordinates()
        {
            try
            {
                _geopostion = SettingsManager.Position;
                if (SettingsManager.IsSelectedLocation) //using saved location
                {
                    return(true);
                }
            }
            catch { }

            //when  using autodetecting
            try
            {
                var device_pos = await GetDevicePosition();

                if (device_pos == null)
                {
                    return(false);
                }

                var device_coor = device_pos.Coordinate.Point.Position;


                if (Math.Abs(device_coor.Latitude - SettingsManager.Position.Latitude) + Math.Abs(device_coor.Longitude - SettingsManager.Position.Longitude) >= 1 || DateTime.Now - SettingsManager.DateCheck >= new TimeSpan(1, 0, 0, 0))
                {
                    var georesult = await MapLocationFinder.FindLocationsAtAsync(new Geopoint(device_coor));

                    if (georesult.Status == MapLocationFinderStatus.Success)
                    {
                        Geoposition.Name         = $"{georesult.Locations[0].Address.Country} {georesult.Locations[0].Address.RegionCode} {georesult.Locations[0].Address.Town}";
                        Geoposition.TimeZone     = TimeZoneInfo.Local.Id;
                        Geoposition.Latitude     = device_coor.Latitude;
                        Geoposition.Longitude    = device_coor.Longitude;
                        Geoposition.Id           = -1;
                        SettingsManager.Position = Geoposition;
                    }
                    else
                    {
                        return(false);
                    }
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
        static double ee = 0.00669342162296594323; //WGS偏心率的平方

        public async System.Threading.Tasks.Task <bool> isInChina(Geopoint pointToReverseGeocode)
        {
            MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

            if (result.Status == MapLocationFinderStatus.Success)
            {
                string CountryCode = result.Locations[0].Address.CountryCode;
                if (CountryCode.Equals("CHN"))
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #4
0
        //通过坐标获取地名
        private async Task <string> GetAddress(Geopoint point)
        {
            BasicGeoposition location = new BasicGeoposition();

            location.Latitude  = 47.643;
            location.Longitude = -122.131;
            Geopoint pointToReverseGeocode = new Geopoint(location);
            MapLocationFinderResult result =
                await MapLocationFinder.FindLocationsAtAsync(point);

            var address = result.Locations[0].Address;

            return(address.Town);
        }
Exemple #5
0
        async Task <MapLocation> GetStreetAddressDetails(Geoposition position)
        {
            MapLocation mapLocation = null;

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

            if (locationResult.Status == MapLocationFinderStatus.Success)
            {
                // We'll take the first one we get back.
                mapLocation = locationResult.Locations.FirstOrDefault();
            }
            return(mapLocation);
        }
        /// <summary>
        /// Returns current location
        /// </summary>
        /// <returns></returns>
        public static async Task GetSinglePositionAsync()
        {
            MapLocationFinderResult result = null;
            Geolocator geolocator          = new Geolocator();

            geolocator.DesiredAccuracyInMeters = 500;
            Geoposition geoposition           = null;
            Geopoint    pointToReverseGeocode = null;

            while (geoposition == null && pointToReverseGeocode == null && result == null)
            {
                geoposition = await geolocator.GetGeopositionAsync();

                longitude = geoposition.Coordinate.Point.Position.Longitude.ToString();
                latitude  = geoposition.Coordinate.Point.Position.Latitude.ToString();


                // reverse geocoding
                BasicGeoposition myLocation = new BasicGeoposition
                {
                    Longitude = Convert.ToDouble(geoposition.Coordinate.Point.Position.Longitude.ToString()),
                    Latitude  = Convert.ToDouble(geoposition.Coordinate.Point.Position.Latitude.ToString())
                };
                pointToReverseGeocode = new Geopoint(myLocation);
                //await Task.Delay(100);
                result = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

                Debug.WriteLine(geolocator.DesiredAccuracyInMeters);
                geolocator.DesiredAccuracyInMeters += 100;
            }


            // Try to get city from location
            try
            {
                cityString = result.Locations[0].Address.Town.ToString().ToLower();
            }
            catch (ArgumentOutOfRangeException e)
            {
                Debug.WriteLine("Array out of range " + e);
                //new MessageDialog("Could not fetch location. Restart the app and try again.").ShowAsync();
                throw;
            }

            await HideLoadingIndicator();


            //Debug.WriteLine(cityString + " " +geolocator.DesiredAccuracyInMeters);
        }
        private async Task <string> GetLocationName(GeoCoordinate coord)
        {
            MapService.ServiceToken = ConfigurationManager.AppSettings["BING_MAPS"];
            var queryPoint = new BasicGeoposition {
                Latitude = coord.Latitude, Longitude = coord.Longitude
            };
            MapLocationFinderResult result =
                await MapLocationFinder.FindLocationsAtAsync(new Geopoint(queryPoint));

            if (result.Status == MapLocationFinderStatus.Success)
            {
                return(result.Locations[0].Address.Town + ", " + result.Locations[0].Address.Region);
            }

            return("Unknown");
        }
        private async Task <string> GetPosition()
        {
            var g   = new Geolocator();
            var pos = await g.GetGeopositionAsync();

            if (pos != null)
            {
                var loc = await MapLocationFinder.FindLocationsAtAsync(pos.Coordinate.Point);

                if (loc != null && loc.Locations.Count > 0)
                {
                    return(loc.Locations.First().Address.Town);
                }
            }
            return("");
        }
Exemple #9
0
        private async void GeMyLocation_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var geolocator = new Geolocator();
            var position   = await geolocator.GetGeopositionAsync();

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

            if (mapLocation.Status == MapLocationFinderStatus.Success)
            {
                MyLocation.Text = mapLocation?.Locations?[0].Address.FormattedAddress;
            }
            else
            {
                MyLocation.Text = "Not Found";
            }
        }
        /// <summary>
        /// Retrieves the city, state, and country for a given location.
        /// </summary>
        /// <param name="loc">Location to geocode.</param>
        /// <param name="ct">Cancellation token.</param>
        /// <returns>String name representing the specified location.</returns>
        public async Task <string> GetCityStateCountryAsync(ILocationModel loc, CancellationToken ct)
        {
            // Reverse geocode the specified geographic location.
            var result = await MapLocationFinder.FindLocationsAtAsync(loc?.AsGeoPoint()).AsTask(ct);

            // If the query returns results, display the name of the town
            // contained in the address of the first result.
            if (result.Status == MapLocationFinderStatus.Success)
            {
                return(loc.LocationDisplayName = this.ConcatAddressParts(3, result.Locations[0].Address?.Town, result.Locations[0].Address?.Region, result.Locations[0].Address?.Country, result.Locations[0].Address?.Continent));
            }
            else
            {
                return(loc.LocationDisplayName = null);
            }
        }
        /// <summary>
        /// Retrieves a formatted address for a given location.
        /// </summary>
        /// <param name="loc">Location to geocode.</param>
        /// <returns>String name representing the specified location.</returns>
        public async Task <string> GetAddressAsync(ILocationModel loc, CancellationToken ct)
        {
            // Reverse geocode the specified geographic location.
            var result = await MapLocationFinder.FindLocationsAtAsync(loc?.AsGeoPoint()).AsTask(ct);

            // If the query returns results, display the name of the town
            // contained in the address of the first result.
            if (result.Status == MapLocationFinderStatus.Success)
            {
                return(loc.LocationDisplayName = result?.Locations[0].Address?.FormattedAddress);
            }
            else
            {
                return(loc.LocationDisplayName = null);
            }
        }
Exemple #12
0
        // ------------------
        // EXTRACTION METHODS
        // ------------------
        private static async Task <string> GetLocation(BasicGeoposition position)
        {
            Geopoint pointToReverseGeocode = new Geopoint(position);

            // 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(result.Locations[0].Address.Town);
            }

            return("");
        }
Exemple #13
0
        public async void myMapControl_Tapped(MapControl sender, MapInputEventArgs args)
        {
            // Start at Grand Central Station.
            //BasicGeoposition startLocation = new BasicGeoposition();
            //startLocation.Latitude = 40.7517;
            //startLocation.Longitude = -073.9766;
            //Geopoint startPoint = new Geopoint(startLocation);
            //// End at Central Park.
            //BasicGeoposition endLocation = new BasicGeoposition();
            //endLocation.Latitude = 40.7669;
            //endLocation.Longitude = -073.9790;
            //Geopoint endPoint = new Geopoint(endLocation);
            //// Get the route between the points.
            //MapRouteFinderResult routeResult =
            //await MapRouteFinder.GetDrivingRouteAsync(
            //  startPoint,
            //  endPoint,
            //  MapRouteOptimization.Time,
            //  MapRouteRestrictions.None,
            //  290);

            Geopoint pointToReverseGeocode = new Geopoint(args.Location.Position);

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

            var resultText = new StringBuilder();

            if (result.Status == MapLocationFinderStatus.Success)
            {
                Popup popups = new Popup();
                //MyPopupContent1 mypopup = new MyPopupContent1();
                popups.Child                 = new MyPopupContent1();
                popups.VerticalOffset        = 250.0;
                popups.HorizontalOffset      = 40.0;
                popups.IsLightDismissEnabled = true;
                popups.IsOpen                = true;
                //        resultText.AppendLine(result.Locations[0].Address.BuildingName + " " +
                //result.Locations[0].Address.Street + ", " + result.Locations[0].Address.Country);
            }



            //MessageDialog msg = new MessageDialog(resultText.ToString());
            //   await msg.ShowAsync();
        }
        /// <summary>
        /// Retrieve addresses for position.
        /// </summary>
        /// <param name="position">Desired position (latitude and longitude)</param>
        /// <returns>Addresses of the desired position</returns>
        public async Task <IEnumerable <Address> > GetAddressesForPositionAsync(Position position, string mapKey = null)
        {
            if (position == null)
            {
                throw new ArgumentNullException(nameof(position));
            }

            SetMapKey(mapKey);

            var queryResults =
                await MapLocationFinder.FindLocationsAtAsync(
                    new Geopoint(new BasicGeoposition {
                Latitude = position.Latitude, Longitude = position.Longitude
            })).AsTask();

            return(queryResults?.Locations?.ToAddresses() ?? null);
        }
        public async Task <MapLocationFinderResult> getLocationData()
        {
            Geolocator geoLocator = new Geolocator {
                DesiredAccuracy = PositionAccuracy.Default
            };
            Geoposition pos = await geoLocator.GetGeopositionAsync();

            BasicGeoposition coords = new BasicGeoposition();

            coords.Latitude  = pos.Coordinate.Point.Position.Latitude;
            coords.Longitude = pos.Coordinate.Point.Position.Longitude;
            Geopoint coordsToReverse = new Geopoint(coords);

            this.locationData = await MapLocationFinder.FindLocationsAtAsync(coordsToReverse);

            return(this.locationData);
        }
        private async void SetLocationMap_MapTapped(MapControl sender, MapInputEventArgs args)
        {
            var selectedLocation = args.Location;
            var mapLocation      = await MapLocationFinder.FindLocationsAtAsync(selectedLocation, 0);

            if (mapLocation.Status == MapLocationFinderStatus.Success)
            {
                string  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:///Leaf.Shared/Assets/Images/mappin.png"));
                mapPin.Location = selectedLocation;
                mapPin.Title    = address;
                SetLocationMap.MapElements.Clear();
                SetLocationMap.MapElements.Add(mapPin);
                MapAddress.Text = address;
            }
        }
Exemple #17
0
        private async Task ReverseGeocodedSearch(Geoposition pos)
        {
            BasicGeoposition location = new BasicGeoposition();

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

            MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(
                pointToReverseGeocode
                );

            if (result.Status == MapLocationFinderStatus.Success)
            {
                LocationSearchbox.Text = result.Locations[0].Address.FormattedAddress;
            }
        }
Exemple #18
0
        /// <summary>
        /// Method to get Car Location
        /// Same as method to get User Location but with different objects for different purposes
        /// </summary>
        private async void getCarLocation()
        {
            if (CarGeolocator.LocationStatus == PositionStatus.Disabled) // checks if Location Settings are enabled
            {
                var enableLocationDialog = new MessageDialog("Please enable Location Settings"
                                                             + "\nCarFindr requires your location to function properly");
                await enableLocationDialog.ShowAsync();

                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-location:")); // redirects to location settings page

                App.Current.Exit();                                                             // closes app safely
            }

            try
            {
                CarGeoposition = await CarGeolocator.GetGeopositionAsync(); // Default is accurate, but inconsistent

                BasicGeoposition queryHint = new BasicGeoposition();
                queryHint.Latitude  = CarGeoposition.Coordinate.Latitude;
                queryHint.Longitude = CarGeoposition.Coordinate.Longitude;
                Geopoint hintPoint = new Geopoint(queryHint);

                // Reverse geocode to specified location
                ParkdInformation = await MapLocationFinder.FindLocationsAtAsync(hintPoint); // null pointer

                DrawCarPushPin(null);
            }
            catch (UnauthorizedAccessException)
            {
                /*
                 * var enableLocationDialog = new MessageDialog("Please enable Location Settings"
                 + "\nCarFindr requires your location to function properly");
                 + enableLocationDialog.ShowAsync();
                 * */
                Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-location:")); // redirects to location settings page
                App.Current.Exit();                                                       // closes app safely
            }
            catch (Exception ex)                                                          // I hate this
            {
                // Something else happened while acquiring the location.
                var unknownErrorDialog = new MessageDialog(ex.Message);
                unknownErrorDialog.ShowAsync();
                App.Current.Exit();
            }
        }
Exemple #19
0
        private async void BTN_QuickEvent_Click(object sender, RoutedEventArgs e)
        {
            if (this._accessToken != null)
            {
                try
                {
                    Geoposition position = await this._mapService.GetUserPosition();

                    //AddressByGeoloc address = await this._apiService.GetAddressAsync(position.Coordinate.Point.Position.Latitude,
                    //    position.Coordinate.Point.Position.Longitude);

                    MapLocationFinderResult finderResult = await MapLocationFinder.FindLocationsAtAsync(position.Coordinate.Point);


                    //EventModel eventModel = new EventModel()
                    //{
                    //    City = address.City,
                    //    Address = address.Address,
                    //    Date = DateTime.Now,
                    //    Name = "Beer !"
                    //};

                    EventModel eventModel = new EventModel();

                    if (finderResult.Status == MapLocationFinderStatus.Success)
                    {
                        var selectedLocation = finderResult.Locations.First();
                        eventModel.Address = String.Format("{0} {1}", selectedLocation.Address.StreetNumber, selectedLocation.Address.Street);
                        eventModel.Date    = DateTime.Now;
                        eventModel.City    = selectedLocation.Address.Town;
                        eventModel.Name    = "Beer !";
                    }

                    this.LeavePage(typeof(CreatePage), eventModel);
                }
                catch (Exception ex)
                {
                    this.GenerateMessageDialog("Une erreur est survenue.");
                }
            }
            else
            {
                this.GenerateMessageDialog("Vous devez être identifié pour posté un event.");
            }
        }
Exemple #20
0
        public static async Task <string> GetPositionNameAsync()
        {
            //new Position();
            var geolocator = new Geolocator {
                DesiredAccuracyInMeters = 20
            };
            Geoposition pos = await geolocator.GetGeopositionAsync();

            var myPoint = new Geopoint(new BasicGeoposition()
            {
                Latitude = pos.Coordinate.Latitude, Longitude = pos.Coordinate.Longitude
            });

            var result =
                await MapLocationFinder.FindLocationsAtAsync(myPoint);

            return(result.Status == MapLocationFinderStatus.Success ? result.Locations[0].Address.Town : null);
        }
        static async Task <IEnumerable <string> > GetAddressesForPositionAsync(Position position)
        {
            var queryResults =
                await
                MapLocationFinder.FindLocationsAtAsync(
                    new Geopoint(new BasicGeoposition {
                Latitude = position.Latitude, Longitude = position.Longitude
            }));

            var addresses = new List <string>();

            foreach (var result in queryResults?.Locations)
            {
                addresses.Add(AddressToString(result.Address));
            }

            return(addresses);
        }
        private async void Mymap_MapTapped(MapControl sender, MapInputEventArgs args)
        {
            Geopoint pointToReverseGeocode = new Geopoint(args.Location.Position);

            //Mostra o local encontrado
            MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(pointToReverseGeocode);

            var resultText = new StringBuilder();

            if (result.Status == MapLocationFinderStatus.Success)
            {
                resultText.AppendLine(result.Locations[0].Address.Street + ", " + result.Locations[0].Address.Town +
                                      ", " + result.Locations[0].Address.Country);
            }
            Morada = resultText.ToString();
            MessageBox(resultText.ToString());
            this.Frame.Navigate(typeof(Addcontact), Morada);
        }
Exemple #23
0
        private async Task <string> reverseGeocodeAsync(Geopoint pointToReverseGeocode)
        {
            // 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)
            {
                MapAddress address = result.Locations.First().Address;
                return(address.FormattedAddress);
            }
            else
            {
                return(null);
            }
        }
Exemple #24
0
        private async void MyMap_MapTapped(MapControl sender, MapInputEventArgs args)
        {
            progressBar.Visibility = Windows.UI.Xaml.Visibility.Visible;
            Geopoint pointToReverseGeocode = new Geopoint(args.Location.Position);

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

            var resultText = new StringBuilder();

            if (result.Status == MapLocationFinderStatus.Success)
            {
                resultText.AppendLine("Location : " + result.Locations[0].Address.District + ", " + result.Locations[0].Address.Town + ", " + result.Locations[0].Address.Country);
            }
            positionTextBlock.Text = resultText.ToString();
            progressBar.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
        }
        private async Task GetCurrentLocation()
        {
            MyProgressRing.IsActive = true;
            MyMap.Opacity           = 0.5;
            try
            {
                if (MyMap.MapElements.Count > Stations.Count)
                {
                    MyMap.MapElements.RemoveAt(MyMap.MapElements.Count - 1);
                }
                var geoLocator = new Geolocator();
                var position   = await geoLocator.GetGeopositionAsync();

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

                if (mapLocation.Status == MapLocationFinderStatus.Success)
                {
                    BasicGeoposition basicGeoposition = new BasicGeoposition();
                    basicGeoposition.Latitude  = position.Coordinate.Point.Position.Latitude;
                    basicGeoposition.Longitude = position.Coordinate.Point.Position.Longitude;
                    Geopoint point = new Geopoint(basicGeoposition);
                    CurrentPosition = point;
                    MapIcon mapIcon = new MapIcon()
                    {
                        Location = point,
                        Title    = "Me"
                    };
                    MyMap.MapElements.Add(mapIcon);
                    MyMap.Center = point;
                    MapScene mp = MapScene.CreateFromLocationAndRadius(new Geopoint(new BasicGeoposition()
                    {
                        Latitude = point.Position.Latitude, Longitude = point.Position.Longitude
                    }), 800);
                    await MyMap.TrySetSceneAsync(mp);
                }
            }
            catch
            {
                MessageDialog m = new MessageDialog("failed to get your location.\nTurn on your location and try again.");
                await m.ShowAsync();
            }
            MyMap.Opacity           = 1;
            MyProgressRing.IsActive = false;
        }
Exemple #26
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(LocationPin location, LocationPin currentLocation)
        {
            bool hasNoAddress = String.IsNullOrEmpty(location.Address);

            if (location.Photo == null)
            {
                location.Photo = new SharedPhoto();
            }
            if (!hasNoAddress)
            {
                return(true);
            }
            else if (location.Position.Latitude == 0 && location.Position.Longitude == 0)
            {
                return(false);
            }

            var results = await MapLocationFinder.FindLocationsAtAsync(location.Geopoint);


            if (results.Status == MapLocationFinderStatus.Success && results.Locations.Count > 0)
            {
                var result = results.Locations.First();

                //This will re-allocate the Position to that particular address.
                //   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);
            }
        }
Exemple #27
0
        private async Task <string> GetCityName(BasicGeoposition position)
        {
            MapService.ServiceToken = "AEKtGCjDSo2UnEvMVxOh~iS-cB5ZHhjZiIJ9RgGtVgw~AkzS_JYlIhjskoO8ziK63GAJmtcF7U_t4Gni6nBb-MncX6-iw8ldj_NgnmUIzMPY";

            Geopoint pointToReverseGeocode = new Geopoint(position);

            //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(result.Locations[0].Address.Town);
            }

            return("");
        }
Exemple #28
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (e.Parameter is string[])
            {
                var stop = await Data.GetBusStop(((string[])e.Parameter)[1], CancellationTokenSource.Token);

                var route = await Data.GetRoute(((string[])e.Parameter)[0], CancellationTokenSource.Token);

                string destination = ((string[])e.Parameter)[2];
                DescriptionBlock.Text = route.Value.Name + " to " + destination + " at " + stop.Value.Name;
                Windows.Devices.Geolocation.Geolocator locator = new Windows.Devices.Geolocation.Geolocator();
                TitleBox.Text = destination;
                string city = null;
                try
                {
                    var finder = await MapLocationFinder.FindLocationsAtAsync(new Windows.Devices.Geolocation.Geopoint(stop.Value.Position));

                    if (finder.Locations.Count > 0)
                    {
                        city = finder.Locations[0].Address.Town;
                        CityContextBox.IsEnabled = true;
                        CityContextBox.Content   = "In " + city;
                    }
                    else
                    {
                        CityContextBox.Content = "(Could not get city)";
                    }
                }
                catch (Exception)
                {
                    CityContextBox.Content = "(Could not get city)";
                }
                location = new ContextLocation()
                {
                    Latitude = stop.Value.Position.Latitude, Longitude = stop.Value.Position.Longitude, City = city
                };
                favorite = new FavoriteArrival()
                {
                    Contexts = new LocationContext[0], Route = route.Value.ID, Stop = stop.Value.ID, Destination = destination
                };
            }
        }
Exemple #29
0
        private async void UpdateAddress()
        {
            MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(_point);

            string res = "";

            try
            {
                res = result.Locations[0].Address.StreetNumber + " " + result.Locations[0].Address.Street + ", " + result.Locations[0].Address.Town;
                Debug.WriteLine(res);
                PlaceName.Text = res;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            res = _point.Position.Latitude + ", " + _point.Position.Longitude;
            await mapControl.TrySetViewAsync(_point, 15, 0, 0, MapAnimationKind.Linear);
        }
        private async void MyMap_MapTapped(MapControl sender, MapInputEventArgs args)
        {
            Geopoint point = new Geopoint(args.Location.Position);


            MapLocationFinderResult FinderResult =
                await MapLocationFinder.FindLocationsAtAsync(point);

            String format = "{0}, {1}, {2}";


            if (FinderResult.Status == MapLocationFinderStatus.Success)
            {
                var selectedLocation = FinderResult.Locations.First();

                string message = String.Format(format, selectedLocation.Address.Town, selectedLocation.Address.District, selectedLocation.Address.Country);
                await ShowMessage(message);
            }
        }