Export (0) Print
Expand All

RouteServiceClient.CalculateRoutesFromMajorRoads Method

This documentation is no longer available on MSDN. It is available as a CHM or PDF download. For the newest Geocoding, Imagery, Routing and Traffic services, see the Bing Maps REST Services

Calculates starting points or route directions to a specified location from nearby major roads.

public MajorRoutesResponse CalculateRoutesFromMajorRoads(MajorRoutesRequest request);

Parameters

request

A MajorRoutesRequest object that contains the header and parameter information for the service operation.

If no major roads are found near the specified MajorRoutesRequest.Destination Property, then the MajorRoutesResponse.StartingPoints Property is returned empty and no routes are calculated.



private void CalculateRoutesFromMajorRoadsRequest()
{
string Results = "";

try
{
// Set a Bing Maps key before making a request
string key = "Bing Maps Key";

RouteService.MajorRoutesRequest majorRoutesRequest = new RouteService.MajorRoutesRequest();

// Set the credentials using a valid Bing Maps Key
majorRoutesRequest.Credentials = new RouteService.Credentials();
majorRoutesRequest.Credentials.ApplicationId = key;

// Set the destination of the routes from major roads
RouteService.Waypoint endPoint = new RouteService.Waypoint();
endPoint.Location = new RouteService.Location();
endPoint.Location.Latitude = 47.608;
endPoint.Location.Longitude = -122.337;
endPoint.Description = "Destination";

// Set the option to return full routes with directions
RouteService.MajorRoutesOptions options = new RouteService.MajorRoutesOptions();
options.ReturnRoutes = true;

majorRoutesRequest.Destination = endPoint;
majorRoutesRequest.Options = options;

// Make the route-from-major-roads request
RouteService.RouteServiceClient routeService =
new RouteService.RouteServiceClient("BasicHttpBinding_IRouteService");
RouteService.MajorRoutesResponse majorRoutesResponse = routeService.CalculateRoutesFromMajorRoads(majorRoutesRequest);

RouteService.RouteLeg leg = new RouteService.RouteLeg();

for (int j = 0; j < majorRoutesResponse.Routes.Length; j++)
{
directions = directions + "<b>Route " + (j+1).ToString() + "</b><br>";

for (int k = 0; k < majorRoutesResponse.Routes[j].Legs.Length; k++)
{
leg = majorRoutesResponse.Routes[j].Legs[k];

for (int i = 0; i < leg.Itinerary.Length; i++)
{
directions = directions + leg.Itinerary[i].Text + "<br>";
}
}
}

Results = directions;


}
catch (Exception ex)
{
Results = "An exception occurred: " + ex.Message;

}

}



    
Show:
© 2014 Microsoft