Esempio n. 1
0
        public static RouteResult GetRoute(GeocodeLocation loc1, GeocodeLocation loc2)
        {
            try
            {
                var routeService = new RouteService();
                var req = new RouteRequest();
                var mreq = new MajorRoutesRequest();
                // Set the credentials using a valid Virtual Earth token
                string token = "AolKu2V0H2w28BS3ZiaImboX02IOwKIS_7P_EhRQ0-cNuGAWqovQ83ISPMjXC_0b";// GetToken();
                req.Credentials = new Credentials();
                req.Credentials.Token = token;

                var wps = new Waypoint[2];
                wps[0] = new Waypoint
                             {
                                 Location = new Location
                                                {
                                                    Latitude = loc1.Latitude,
                                                    Longitude = loc1.Longitude
                                                }
                             };
                wps[1] = new Waypoint
                             {
                                 Location = new Location
                                                {
                                                    Latitude = loc2.Latitude,
                                                    Longitude = loc2.Longitude
                                                }
                             };

                req.Waypoints = wps;

                req.Options = new RouteOptions
                                  {
                                      Optimization = RouteOptimization.MinimizeDistance,
                                      RoutePathType = RoutePathType.Points,
                                      Mode = TravelMode.Driving
                                  };

                req.UserProfile = new UserProfile
                                      {
                                          DistanceUnit = DistanceUnit.Kilometer
                                      };

                RouteResponse response = routeService.CalculateRoute(req);

                if (response.Result != null)
                    return response.Result;

            }
            catch (Exception ex)
            {
                return null;
            }
            return null;
        }
Esempio n. 2
0
 /// <remarks/>
 public void CalculateRouteAsync(RouteRequest request)
 {
     this.CalculateRouteAsync(request, null);
 }
Esempio n. 3
0
 /// <remarks/>
 public void CalculateRouteAsync(RouteRequest request, object userState)
 {
     if ((this.CalculateRouteOperationCompleted == null)) {
         this.CalculateRouteOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCalculateRouteOperationCompleted);
     }
     this.InvokeAsync("CalculateRoute", new object[] {
                                                         request}, this.CalculateRouteOperationCompleted, userState);
 }
Esempio n. 4
0
 /// <remarks/>
 public System.IAsyncResult BeginCalculateRoute(RouteRequest request, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("CalculateRoute", new object[] {
                                                                request}, callback, asyncState);
 }