Ejemplo n.º 1
0
        public static RouteService.RouteServiceClient GetRouteService(DependencyObject obj = null)
        {
            RouteService.RouteServiceClient service = null;
            if (IsDesignMode(obj))
            {
                Binding binding = new BasicHttpBinding();
                EndpointAddress address = new EndpointAddress("http://dev.virtualearth.net/webservices/v1/geocodeservice/GeocodeService.svc");
                service = new RouteService.RouteServiceClient(binding, address);
            }
            else
            {
                service = new RouteService.RouteServiceClient("CustomBinding_IRouteService");
            }

            return service;
        }
        /*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);

            }
        }
Ejemplo n.º 3
0
        private void CalculateRoute(GeocodeService.GeocodeResult[] results)
        {
            RouteService.RouteServiceClient routeService = new RouteService.RouteServiceClient("BasicHttpBinding_IRouteService");

            routeService.CalculateRouteCompleted += new EventHandler <RouteService.CalculateRouteCompletedEventArgs>(routeService_CalculateRouteCompleted);

            RouteService.RouteRequest routeRequest = new RouteService.RouteRequest();
            routeRequest.Credentials = new Credentials();
            routeRequest.Credentials.ApplicationId = ((ApplicationIdCredentialsProvider)myMap.CredentialsProvider).ApplicationId;

            routeRequest.Options = new RouteService.RouteOptions();
            routeRequest.Options.RoutePathType = RouteService.RoutePathType.Points;

            routeRequest.Waypoints = new System.Collections.ObjectModel.ObservableCollection <RouteService.Waypoint>();

            foreach (GeocodeService.GeocodeResult result in results)
            {
                routeRequest.Waypoints.Add(GeoCodeResultToWaypoint(result));
            }
            routeService.CalculateRouteAsync(routeRequest);
        }
        private void GetRoute(List<Stop> stops)
        {
            // Create the service variable and set the callback method using the CalculateRouteCompleted property.
            RouteService.RouteServiceClient routeService = new RouteService.RouteServiceClient("BasicHttpBinding_IRouteService");
            routeService.CalculateRouteCompleted += new EventHandler<RouteService.CalculateRouteCompletedEventArgs>(routeService_CalculateRouteCompleted);

            // Set the token.
            RouteService.RouteRequest routeRequest = new RouteService.RouteRequest();
            routeRequest.Credentials = new Credentials();
            routeRequest.Credentials.ApplicationId = ((ApplicationIdCredentialsProvider)map1.CredentialsProvider).ApplicationId;

            // Return the route points so the route can be drawn.
            routeRequest.Options = new RouteService.RouteOptions();
            routeRequest.Options.RoutePathType = RouteService.RoutePathType.Points;

            routeRequest.Waypoints = new System.Collections.ObjectModel.ObservableCollection<RouteService.Waypoint>();
            int max = stops.Count() > 25 ? 25 : stops.Count();
            for (int i = 0; i < max; i++)
            {
                Stop stop = stops.ElementAt(i);
                RouteService.Waypoint srcWaypoint = new RouteService.Waypoint();
                srcWaypoint.Location = new GeoCoordinate((double)stop.Latitude, (double)stop.Longitude);
                routeRequest.Waypoints.Add(srcWaypoint);
            }

            // Make the CalculateRoute asnychronous request.
            routeService.CalculateRouteAsync(routeRequest);
        }