Example #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;
        }
Example #2
0
 /// <remarks/>
 public void CalculateRoutesFromMajorRoadsAsync(MajorRoutesRequest request)
 {
     this.CalculateRoutesFromMajorRoadsAsync(request, null);
 }
Example #3
0
 /// <remarks/>
 public void CalculateRoutesFromMajorRoadsAsync(MajorRoutesRequest request, object userState)
 {
     if ((this.CalculateRoutesFromMajorRoadsOperationCompleted == null)) {
         this.CalculateRoutesFromMajorRoadsOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCalculateRoutesFromMajorRoadsOperationCompleted);
     }
     this.InvokeAsync("CalculateRoutesFromMajorRoads", new object[] {
                                                                        request}, this.CalculateRoutesFromMajorRoadsOperationCompleted, userState);
 }
Example #4
0
 /// <remarks/>
 public System.IAsyncResult BeginCalculateRoutesFromMajorRoads(MajorRoutesRequest request, System.AsyncCallback callback, object asyncState)
 {
     return this.BeginInvoke("CalculateRoutesFromMajorRoads", new object[] {
                                                                               request}, callback, asyncState);
 }