RouteServiceSoap.CalculateRoute Method
RouteServiceSoap.CalculateRoute Method
Calculates the itinerary of a route and/or the calculated route representation (used to render a highlighted route), based on identified route segments and options. Returns a Route object.
Public Function CalculateRoute _
( ByVal specification As RouteSpecification ) As Route
[C#]
public Route CalculateRoute ( RouteSpecification specification );
Parameters
- specification
The route (RouteSpecification object) to calculate.
Remarks
When calling the CalculateRoute method, the Location property for a Waypoint can only be defined using an instance of LatLong. CalculateRoute uses only latitude/longitude data, and cannot accept other types of location data, such as an address.
A route can include up to 50 waypoints; that is, the start point, up to 48 intermediate stops, and end point of the route.
The total distance of a route cannot be longer than 50,000 kilometers; otherwise, a SOAP fault is returned.
The total time for a driving day cannot be less than 60 minutes, as this will result in an exception. Set the length of the driving day by setting the DayEndTime and DayStartTime properties of the DriverProfile class.
To calculate a route itinerary based on latitude and longitude coordinates and default options, use the RouteServiceSoap.CalculateSimpleRoute method.
To render a route on a map, use the RenderServiceSoap.GetMap method.
You can specify road preferences by setting the DriverProfile.PreferredRoadTypes property, and by setting the SegmentOptions.Preference property to SegmentPreference.PreferredRoads.
Example
[Visual Basic]
'Route between Seattle, WA, and Portland, OR
Dim findService As New FindServiceSoap()
Dim findSpec As New FindSpecification()
findSpec.DataSourceName = "MapPoint.NA"
findSpec.InputPlace = "Seattle, WA"
Dim startResult As FindResults = findService.Find(findSpec)
findSpec.InputPlace = "Portland, OR"
Dim endResult As FindResults = findService.Find(findSpec)
Dim routeSegmentsSpec(1) As SegmentSpecification
routeSegmentsSpec(0) = New SegmentSpecification()
routeSegmentsSpec(0).Waypoint = New Waypoint()
routeSegmentsSpec(0).Waypoint.Name = startResult.Results(0).FoundLocation.Entity.Name
routeSegmentsSpec(0).Waypoint.Location = startResult.Results(0).FoundLocation
routeSegmentsSpec(1) = New SegmentSpecification()
routeSegmentsSpec(1).Waypoint = New Waypoint()
routeSegmentsSpec(1).Waypoint.Name = endResult.Results(0).FoundLocation.Entity.Name
routeSegmentsSpec(1).Waypoint.Location = endResult.Results(0).FoundLocation
Dim routeSpec As New RouteSpecification()
routeSpec.DataSourceName = "MapPoint.NA"
routeSpec.Segments = routeSegmentsSpec
Dim routeService As New RouteServiceSoap()
Dim myRoute As Route
myRoute = routeService.CalculateRoute(routeSpec)
Dim i As Integer
For i = 0 To myRoute.Itinerary.Segments(0).Directions.Length - 1
Console.WriteLine(myRoute.Itinerary.Segments(0).Directions(i).Instruction)
Next i
[C#]
//Route between Seattle, WA, and Portland, OR
FindServiceSoap findService = new FindServiceSoap();
FindSpecification findSpec = new FindSpecification();
findSpec.DataSourceName = "MapPoint.NA";
findSpec.InputPlace = "Seattle, WA";
FindResults startResult = findService.Find(findSpec);
findSpec.InputPlace = "Portland, OR";
FindResults endResult = findService.Find(findSpec);
SegmentSpecification[] routeSegmentsSpec = new SegmentSpecification[2];
routeSegmentsSpec[0] = new SegmentSpecification();
routeSegmentsSpec[0].Waypoint = new Waypoint();
routeSegmentsSpec[0].Waypoint.Name = startResult.Results[0].FoundLocation.Entity.Name;
routeSegmentsSpec[0].Waypoint.Location = startResult.Results[0].FoundLocation;
routeSegmentsSpec[1] = new SegmentSpecification();
routeSegmentsSpec[1].Waypoint = new Waypoint();
routeSegmentsSpec[1].Waypoint.Name = endResult.Results[0].FoundLocation.Entity.Name;
routeSegmentsSpec[1].Waypoint.Location = endResult.Results[0].FoundLocation;
RouteSpecification routeSpec = new RouteSpecification();
routeSpec.DataSourceName = "MapPoint.NA";
routeSpec.Segments = routeSegmentsSpec;
RouteServiceSoap routeService = new RouteServiceSoap();
Route myRoute;
myRoute = routeService.CalculateRoute(routeSpec);
for(int i = 0; i < myRoute.Itinerary.Segments[0].Directions.Length ; i++)
{
Console.WriteLine(myRoute.Itinerary.Segments[0].Directions[i].Instruction);
}
See Also
RouteServiceSoap Class | Route Class | RouteSpecification Class | RouteServiceSoap.CalculateSimpleRoute Method | RenderServiceSoap.GetMap Method