0

好像routeService.CalculateRoute(routeRequest)没有生效routeRequest.Options。我尝试过设置RouteOptimization.MinimizeDistanceRouteOptimization.MinimizeTime;但似乎都没有调整到最佳路线。似乎CalculateRoute 总是根据它们在航点数组中的顺序来计算航点。有谁知道我做错了什么?

            Waypoint[] waypoints = new Waypoint[waypointInfo.Count + 1]; // +1 for the store

            waypoints[0] = new Waypoint();
            waypoints[0].Description = "Store";
            waypoints[0].Location = new RouteService.Location();
            waypoints[0].Location.Latitude = store.Latitude;
            waypoints[0].Location.Longitude = store.Longitude;

            for (int i = 0; i < waypointInfo.Count; i++)
            {
                waypoints[i+1] = new Waypoint();
                waypoints[i + 1].Description = waypointInfo[i].Address+ " - " +waypointInfo[i].Name;
                waypoints[i+1].Location = new RouteService.Location();
                waypoints[i + 1].Location.Latitude = waypointInfo[i].locations.Latitude;
                waypoints[i + 1].Location.Longitude = waypointInfo[i].locations.Longitude;

            }



            RouteRequest routeRequest = new RouteRequest();
            routeRequest.Credentials = new Microsoft.Maps.MapControl.WPF.Credentials();
            routeRequest.Credentials.ApplicationId = "BING API KEY";

            // You want minimum distance or minimum time?
            RouteOptions myROuteOptions = new RouteOptions();
            myROuteOptions.Mode = TravelMode.Driving;
            myROuteOptions.Optimization = RouteOptimization.MinimizeDistance;
            myROuteOptions.TrafficUsage = TrafficUsage.TrafficBasedTime;
            routeRequest.Options = myROuteOptions;

            //routeRequest.UserProfile = new UserProfile { DistanceUnit = RouteService.DistanceUnit.Kilometer };

            routeRequest.Waypoints = waypoints;

            // Make the calculate route request
            RouteServiceClient routeService = new RouteServiceClient();
            RouteResponse routeResponse = routeService.CalculateRoute(routeRequest);



            double dayDistance = 0;               
            directions.Clear();

            if (routeResponse.Result.Legs.Length > 0)
            {
                int instructionCount = 0;
                int legCount = 0;

                foreach (RouteLeg leg in routeResponse.Result.Legs)
                {

                    legCount++;
                    if (legCount > 1)
                    {
                        directions.Append(" " + "\n");
                    }

                    foreach (ItineraryItem item in leg.Itinerary)
                    {

                        instructionCount++;
                        directions.Append(string.Format("{0}. {1} {2}\n",
                            instructionCount, item.Summary.Distance, item.Text));
                        dayDistance += item.Summary.Distance;
                    }
                }

}

4

3 回答 3

1

The waypoints你用的完全按照你说的做。他们对 Bing 说,路线应该完全按照这个顺序。所以它工作得很好,你没有做错任何事。

http://msdn.microsoft.com/en-us/library/cc966873.aspx

于 2013-07-17T20:36:34.793 回答
1

我认为CalculateRoute 不会重新排序航点。RouteOptimization 仅影响在指定路线中的任意两个连续航点之间选择哪条路径。

于 2013-07-18T20:05:18.983 回答
0

在您的情况下,您修复了路线必须经过的点,如果您没有在“开始”和“结束”之间提供过多的航点,您可以看到优化的差异。

我尝试了您的代码,但它说我必须将端点作为参数传递:

RouteServiceClient routeService = new RouteServiceClient("Here");

知道如何解决这个问题

于 2014-03-13T21:28:03.577 回答