void proxy_ReverseGeocodeCompleted(object sender, GeocodeService.ReverseGeocodeCompletedEventArgs e) { // e.Result.Results[0].Address.District = "BY" //proxy.ReverseGeocodeCompleted -= proxy_ReverseGeocodeCompleted; if (ResolveAddressCompleted != null) { ResolveAddressCompleted(sender, new ResolveAddressCompletedEventArgs( e.Result != null ? new CivicAddress() { AddressLine1 = e.Result.Results[0].Address.AddressLine, AddressLine2 = e.Result.Results[0].Address.FormattedAddress, Building = "", City = e.Result.Results[0].Address.Locality, CountryRegion = e.Result.Results[0].Address.CountryRegion, FloorLevel = "0", PostalCode = e.Result.Results[0].Address.PostalCode, StateProvince = e.Result.Results[0].Address.PostalTown } : null, e.Error, e.Cancelled, e.UserState) ); } }
/*oblicza trasę na podstawie otrzymanych współrzędnych * jesli waypointów mniej niż dwa informacja * w przeciwnym wypadku zapisz je na mapie */ public void CalculateRoute(Microsoft.Phone.Controls.Maps.Map map, GeocodeService.GeocodeResult[] coordinates, Helper.MapResultReceived croute, TravelMode tm = TravelMode.Driving) { if (coordinates.Length < 2) { MessageBox.Show("Too small number od location: you need startPoint and endpoint at least"); return; } try { MapResponseSendHere = new Helper.MapResultReceived(croute); routedMap = map; RouteService.RouteServiceClient routeService = new RouteService.RouteServiceClient("BasicHttpBinding_IRouteService"); routeService.Endpoint.Binding.ReceiveTimeout = timeout; routeService.Endpoint.Binding.SendTimeout = timeout; routeService.Endpoint.Binding.OpenTimeout = timeout; RouteRequest routeRequest = new RouteRequest(); { routeRequest.Credentials = new Microsoft.Phone.Controls.Maps.Credentials() { ApplicationId = bingMapKey }; routeRequest.Options = new RouteService.RouteOptions() { RoutePathType = RouteService.RoutePathType.Points, Mode = tm }; } routeRequest.Waypoints = new System.Collections.ObjectModel.ObservableCollection<RouteService.Waypoint>(); foreach (GeocodeService.GeocodeResult coord in coordinates) { if (null != coord) { if (coordinates[coordinates.Length - 1] != coord) //jesli to ostatni punkt ustaw: MOBICA routeRequest.Waypoints.Add(GeocodeToWaypoint(coord)); else routeRequest.Waypoints.Add(GeocodeToWaypoint(coord, "MOBICA")); } } routeService.CalculateRouteCompleted += (sender, e) => CalculateRouteCompleted(sender, e); routeService.CalculateRouteAsync(routeRequest, coordinates.Length); } catch (Exception ex) { MessageBox.Show("An exception occurred: " + ex.Message); } }
//otrzymane współrzędne zostaną wysłane na zapisaną wcześniej do słownika funkcję private void GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e) { if (e.Result.Results.Count > 0) { GeocodeResult coordinatesReceived = e.Result.Results[0]; //MessageBox.Show("Latitude: " + coordinatesReceived.Locations[0].Latitude + "\nLongitude: " + coordinatesReceived.Locations[0].Longitude); if (GeocodeResponseSendHere.ContainsKey(System.Convert.ToInt32(e.UserState))) { GeocodeResponseSendHere[System.Convert.ToInt32(e.UserState)](coordinatesReceived); GeocodeResponseSendHere.Remove(System.Convert.ToInt32(e.UserState)); } } else MessageBox.Show("No location found"); }
private RouteService.Waypoint GeocodeResultToWaypoint(GeocodeService.GeocodeResult result) { RouteService.Waypoint waypoint = new RouteService.Waypoint(); waypoint.Description = result.DisplayName; waypoint.Location = new RouteService.Location(); waypoint.Location.Latitude = result.Locations[0].Latitude; waypoint.Location.Longitude = result.Locations[0].Longitude; return waypoint; }
// This method makes the initial CalculateRoute asynchronous request using the results of the Geocode Service. private void CalculateRoute(GeocodeService.GeocodeResult[] locations) { // Create the service variable and set the callback method using the CalculateRouteCompleted property. RouteServiceClient routeService = new RouteServiceClient("BasicHttpBinding_IRouteService"); routeService.CalculateRouteCompleted += new EventHandler<CalculateRouteCompletedEventArgs>(routeService_CalculateRouteCompleted); // Set the credentials. RouteService.RouteRequest routeRequest = new RouteService.RouteRequest(); routeRequest.Culture = MyMap.Culture; routeRequest.Credentials = new RouteService.Credentials(); routeRequest.Credentials.ApplicationId = ((ApplicationIdCredentialsProvider)MyMap.CredentialsProvider).ApplicationId; // Return the route points so the route can be drawn. routeRequest.Options = new RouteService.RouteOptions(); routeRequest.Options.RoutePathType = RouteService.RoutePathType.Points; // Set the waypoints of the route to be calculated using the Geocode Service results stored in the geocodeResults variable. routeRequest.Waypoints = new System.Collections.ObjectModel.ObservableCollection<RouteService.Waypoint>(); foreach (GeocodeService.GeocodeResult result in locations) { routeRequest.Waypoints.Add(GeocodeResultToWaypoint(result)); } // Make asynchronous call to fetch the data ... pass state object. // Make the CalculateRoute asnychronous request. routeService.CalculateRouteAsync(routeRequest); }
// This is the Geocode request callback method. private void geocodeService_GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e) { // Retrieve the user state of this response (the ‘waypoint index’) to identify which geocode request // it corresponds to. int waypointIndex = System.Convert.ToInt32(e.UserState); // Retrieve the GeocodeResult for this response and store it in the global variable geocodeResults, using // the waypoint index to position it in the array. geocodeResults[waypointIndex] = e.Result.Results[0]; // Look at each element in the global gecodeResults array to figure out if more geocode responses still // need to be returned. bool doneGeocoding = true; foreach (GeocodeService.GeocodeResult gr in geocodeResults) { if (gr == null) { doneGeocoding = false; } } // If the geocodeResults array is totally filled, then calculate the route. if (doneGeocoding) { //Clear any existing routes ClearRoute(); //Calculate the route CalculateRoute(geocodeResults); } }
void geocodeClient_GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e) { if (e.Error == null) { if (e.Result.Results.Count > 0) { foreach (var item in e.Result.Results) { //Debug.WriteLine(item.Locations[0].Latitude.ToString()); //Debug.WriteLine(item.Locations[0].Longitude.ToString()); //Debug.WriteLine(item.Address.FormattedAddress.ToString()); GeoItemViewModel geoItem = new GeoItemViewModel(); geoItem.Latitude = item.Locations[0].Latitude.ToString(); geoItem.Longitude = item.Locations[0].Longitude.ToString(); geoItem.AddressLine = item.Address.FormattedAddress.ToString(); this.Items.Add(geoItem); this.IsAddressResult = true; NotifyPropertyChanged("AddressResultVisibility"); } this.IsDataLoaded = true; } else { //Debug.WriteLine("no results"); this.IsAddressResult = false; NotifyPropertyChanged("AddressResultVisibility"); this.IsDataLoaded = false; } } else { //Debug.WriteLine("Geocode Error"); MessageBox.Show("Error in Geocoding Service! Please go back and try again."); } }
private void geocodeService_GeocodeCompleted(object sender, GeocodeService.GeocodeCompletedEventArgs e) { try { if (e.Error == null && e.Result.Results.Count() > 0) { GeocodeResult result = e.Result.Results[0]; addPushPinToLocation(result.Locations[0]); } } catch (Exception) { throw; } }
private void geocodeService_ReverseGeocodeCompleted(object sender, GeocodeService.ReverseGeocodeCompletedEventArgs e) { try { if (e.Error == null && e.Result.Results.Count() > 0) { GeocodeResult result = e.Result.Results[0]; String formattedAddress = result.Address.FormattedAddress; getPointFromAddress(formattedAddress); } } catch (Exception ) { throw ; } }