は を有効にしてrouteService.CalculateRoute(routeRequest)
いないようrouteRequest.Options
です。RouteOptimization.MinimizeDistance
設定を試み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;
}
}
}