private async Task<string> GetCityByLocation(Location myLocation) { ReverseGeocodeRequestOptions requestOptions = new ReverseGeocodeRequestOptions(myLocation); SearchManager manager = this.Map.SearchManager; LocationDataResponse responce = await manager.ReverseGeocodeAsync(requestOptions); return responce.LocationData.First().Address.AdminDistrict2; }
/// <summary> /// Handles the Loaded event of the myMap control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private async void myMap_Loaded(object sender, RoutedEventArgs e) { try { this.MyMap = (Map)sender; Geolocator geolocator = new Geolocator(); //used to obtain user location Geoposition position = await geolocator.GetGeopositionAsync(); double latitude = position.Coordinate.Point.Position.Latitude; double longitude = position.Coordinate.Point.Position.Longitude; Location location = new Location(latitude, longitude); SearchManager searchManager = MyMap.SearchManager; ReverseGeocodeRequestOptions requestOptions = new ReverseGeocodeRequestOptions(location); LocationDataResponse response; do { response = await searchManager.ReverseGeocodeAsync(requestOptions); } while (response.LocationData.Count == 0 || response.LocationData == null); GeocodeLocation currentLocation = response.LocationData[0]; //place a PushPin at the right place (user) CustomPushPin userPin = new CustomPushPin(location); userPin.Pin.Style = this.Resources["PushPinStyle"] as Style; //create the associated toolTip ToolTipService.SetToolTip(userPin.Pin, "Vous"); MyMap.Children.Add(userPin.Pin); MyMap.ZoomLevel = 12; MyMap.Center = location; //used to retrieve shops PagesJaunesShopRetriever retriever = new PagesJaunesShopRetriever(); bool nothing = await retriever.GetShops(currentLocation.Address.Locality, this.Model); this.shopsViewSource.Source = this.Model.Shops; this.ShopViews = new List <ShopView>(); //used to display shops this.ShopViews = await this.createShopViews(this.Model.Shops, searchManager); foreach (ShopView shopView in this.ShopViews) { this.MyMap.Children.Add(shopView.Pin.Pin); } } catch (Exception ex) { } }
static async Task<IEnumerable<string>> GetAddressesForPositionAsync(Position position) { var results = new List<string>(); var source = new TaskCompletionSource<IEnumerable<string>>(); var requestOptions = new ReverseGeocodeRequestOptions(new Location(position.Latitude, position.Longitude)); var response = await new Bing.Maps.Map { Credentials = FormsMaps.AuthenticationToken }.SearchManager.ReverseGeocodeAsync(requestOptions); if (!response.HasError) { foreach (var address in response.LocationData) results.Add(address.Address.FormattedAddress); } return results; }
static async Task <IEnumerable <string> > GetAddressesForPositionAsync(Position position) { var results = new List <string>(); var source = new TaskCompletionSource <IEnumerable <string> >(); var requestOptions = new ReverseGeocodeRequestOptions(new Location(position.Latitude, position.Longitude)); var response = await new Bing.Maps.Map { Credentials = FormsMaps.AuthenticationToken }.SearchManager.ReverseGeocodeAsync(requestOptions); if (!response.HasError) { foreach (var address in response.LocationData) { results.Add(address.Address.FormattedAddress); } } return(results); }
protected async override void OnNavigatedTo(NavigationEventArgs e) { if (e.Parameter != null) { var item = e.Parameter as UK_Stadium_Finder.DataModels.StadiumItem; destinationLocation = new Location(Convert.ToDouble(item.Latitude), Convert.ToDouble(item.Longitude)); ReverseGeocodeRequestOptions reverseOptions = new ReverseGeocodeRequestOptions(destinationLocation); await GetReverseGeocodeAddress(reverseOptions, false); DirectionsMap.SetView(destinationLocation, new TimeSpan(0, 0, 0, 1, 0)); SetPin(destinationLocation, "D"); } base.OnNavigatedTo(e); }
private async Task GetReverseGeocodeAddress(ReverseGeocodeRequestOptions reverseRequestOptions, bool to) { SearchManager search = DirectionsMap.SearchManager; var location = await search.ReverseGeocodeAsync(reverseRequestOptions); if (!location.HasError) { if (to) { FromTextBox.Text = location.LocationData[0].Name; } else { ToTextBox.Text = location.LocationData[0].Name; } } }
private async void DirectionsAppBarButton_Click(object sender, RoutedEventArgs e) { Waypoint start = new Waypoint(currentLocation); ; Waypoint end = new Waypoint(destinationLocation); WaypointCollection waypoints = new WaypointCollection() { start, end }; ReverseGeocodeRequestOptions reverseRequestOptions = new ReverseGeocodeRequestOptions(currentLocation); await GetReverseGeocodeAddress(reverseRequestOptions, true); reverseRequestOptions.Location = destinationLocation; await GetReverseGeocodeAddress(reverseRequestOptions, false); directionsManager.RequestOptions.RouteMode = routeMode; directionsManager.Waypoints = waypoints; await directionsManager.CalculateDirectionsAsync(); // Check if route found if (directionsManager.RouteResult.Count > 0) { Instructions.Content = directionsManager.RouteSummaryView; itenaryItems = directionsManager.RouteResult[0].RouteLegs[0].ItineraryItems; } else { Instructions.Content = null; RouteMode.Text = string.Format("{0}: No route found", routeMode.ToString()); } if (DirectionsPanel.Visibility == Visibility.Collapsed) { OpenDirectionsButton.Visibility = Visibility.Collapsed; DirectionsPanel.Visibility = Visibility.Visible; } }
private async void LocateMeAppBarButton_Click(object sender, RoutedEventArgs e) { try { Geoposition position = await _gelocator.GetGeopositionAsync(); _isLocationAvailable = true; Geopoint coords = position.Coordinate.Point; currentLocation = new Location(coords.Position.Latitude, coords.Position.Longitude); DirectionsMap.SetView(currentLocation, new TimeSpan(0, 0, 0, 1, 0)); currentLocationPin.Background = new SolidColorBrush(Colors.Red); MapLayer.SetPosition(currentLocationPin, currentLocation); if (!mapLayer.Children.Contains(currentLocationPin)) { mapLayer.Children.Add(currentLocationPin); Animations.PushpinAnimations.Bounce(currentLocationPin, null, 3000); } ReverseGeocodeRequestOptions reverseOptions = new ReverseGeocodeRequestOptions(currentLocation); await GetReverseGeocodeAddress(reverseOptions, true); } catch (Exception) { _isLocationAvailable = false; } this.DirectionsAppBarButton.IsEnabled = _isLocationAvailable; }
private async void SetNewPosition(Geoposition position) { await this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => { Geoposition newPosition = position; Geocoordinate coord = newPosition.Coordinate; var current = coord.Point; currentLocation.Latitude = current.Position.Latitude; currentLocation.Longitude = current.Position.Longitude; ReverseGeocodeRequestOptions reverseOptions = new ReverseGeocodeRequestOptions(currentLocation); await GetReverseGeocodeAddress(reverseOptions, true); DirectionsMap.SetView(currentLocation, new TimeSpan(0, 0, 0, 1, 0)); MapLayer.SetPosition(currentLocationPin, currentLocation); }); }
private static async Task<IEnumerable<string>> GetAddressesForPositionAsync(Position position) { List<string> results = new List<string>(); #if WINDOWS_APP CreateSearchManager(); Location location = new Location(position.Latitude, position.Longitude); ReverseGeocodeRequestOptions options = new ReverseGeocodeRequestOptions(location); //options.IncludeEntityTypeFlags = ReverseGeocodeEntityType.Address | ReverseGeocodeEntityType.Neighborhood | ReverseGeocodeEntityType.Postcode | ReverseGeocodeEntityType.PopulatedPlace; LocationDataResponse response = await _manager.ReverseGeocodeAsync(options); foreach(GeocodeLocation l in response.LocationData) { results.Add(l.Address.FormattedAddress); } #else MapLocationFinderResult result = await MapLocationFinder.FindLocationsAtAsync(new Windows.Devices.Geolocation.Geopoint(new Windows.Devices.Geolocation.BasicGeoposition() { Latitude = position.Latitude, Longitude = position.Longitude })); if(result.Status == MapLocationFinderStatus.Success) { foreach(MapLocation location in result.Locations) { if(location.Address != null) { results.Add(AddressToString(location.Address)); } } } #endif return results; }