Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Bing RouteOptimization对routeService.CalculateRoute没有任何影响_C#_Wpf_Bing Maps - Fatal编程技术网

C# Bing RouteOptimization对routeService.CalculateRoute没有任何影响

C# Bing RouteOptimization对routeService.CalculateRoute没有任何影响,c#,wpf,bing-maps,C#,Wpf,Bing Maps,似乎routeService.calculateRouteRequest(routeRequest)没有使routeRequest.Options生效。我已尝试设置RouteOptimization.minimizedInstance和RouteOptimization.MinimizeTime和两者似乎都不适合最佳路线。似乎CalculateRoute总是根据航路点在航路点数组中的顺序来计算航路点。有人知道我做错了什么吗 Waypoint[] waypoints = n

似乎
routeService.calculateRouteRequest(routeRequest)
没有使
routeRequest.Options
生效。我已尝试设置
RouteOptimization.minimizedInstance
RouteOptimization.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;
                    }
                }
Waypoint[]航路点=新航路点[waypointInfo.Count+1];//+商店1英镑
航路点[0]=新航路点();
航路点[0]。Description=“Store”;
航路点[0]。位置=新RouteService.Location();
航路点[0]。Location.Latitude=store.Latitude;
航路点[0]。Location.Longitude=store.Longitude;
对于(int i=0;i0)
{
int指令计数=0;
int-legCount=0;
foreach(RouteLeg leg leg in routerresponse.Result.Legs)
{
legCount++;
如果(legCount>1)
{
方向。追加(“+”\n”);
}
foreach(航段中的行程项目。行程)
{
指令计数++;
Append(string.Format(“{0}.{1}{2}\n”,
指令计数,item.Summary.Distance,item.Text);
Dayddistance+=item.Summary.Distance;
}
}

}
您使用的航路点与您所说的完全一致。他们对Bing说,路线应该完全按照这个顺序。所以它工作得很好,你没有做错任何事


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

在您的情况下,您可以确定路线必须经过的点,如果您在“开始”和“结束”之间没有给出过多的航路点,您可以看到优化的差异

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

RouteServiceClient routeService = new RouteServiceClient("Here");
你知道怎么解决这个问题吗