SegmentOptions.Preference Property

SegmentOptions.Preference Property

Indicates whether the route segment is calculated using the quickest route, the shortest route, or by using the preferences specified in the PreferredRoadTypes class.


Public Preference As SegmentPreference


[C#]

public SegmentPreference Preference;

Remarks

  • The Preference property is set by using the SegmentPreference enumeration.

  • Quickest means the segment is calculated as the fastest route based on posted speed limits. Shortest means the segment is calculated as the shortest route based on distance regardless of speed limits. The shortest route is not necessarily the fastest route.

  • You can specify road preferences by setting the DriverProfile.PreferredRoadTypes property, and by setting the Preference property to SegmentPreference.PreferredRoads.

Example

[Visual Basic]

'Route between two locations
Dim startLocation As New Location()
Dim endLocation As New Location()
startLocation.LatLong = New LatLong()
endLocation.LatLong = New LatLong()
startLocation.LatLong.Latitude = 40
startLocation.LatLong.Longitude = -120
endLocation.LatLong.Latitude = 41
endLocation.LatLong.Longitude = -121

Dim routeSegmentsSpec(1) As SegmentSpecification
routeSegmentsSpec(0) = New SegmentSpecification()
routeSegmentsSpec(0).Waypoint = New Waypoint()
routeSegmentsSpec(0).Waypoint.Name = "Start"
routeSegmentsSpec(0).Waypoint.Location = startLocation
routeSegmentsSpec(1) = New SegmentSpecification()
routeSegmentsSpec(1).Waypoint = New Waypoint()
routeSegmentsSpec(1).Waypoint.Name = "End"
routeSegmentsSpec(1).Waypoint.Location = endLocation

'Calculate the shortest route instead of the quickest
'and don't return a map view for each direction
routeSegmentsSpec(0).Options = New SegmentOptions()
routeSegmentsSpec(0).Options.Preference = SegmentPreference.Shortest
routeSegmentsSpec(0).Options.CalculateDirectionMapView = False

Dim routeSpec As New RouteSpecification()
routeSpec.DataSourceName = "MapPoint.NA"
routeSpec.Segments = routeSegmentsSpec

Dim myRoute As Route
myRoute = routeService.CalculateRoute(routeSpec)



[C#]

//Route between two locations
Location startLocation = new Location();
Location endLocation = new Location();
startLocation.LatLong = new LatLong();
endLocation.LatLong = new LatLong();
startLocation.LatLong.Latitude = 40;
startLocation.LatLong.Longitude = -120;
endLocation.LatLong.Latitude = 41;
endLocation.LatLong.Longitude = -121;

SegmentSpecification[] routeSegmentsSpec = new SegmentSpecification[2];
routeSegmentsSpec[0] = new SegmentSpecification();
routeSegmentsSpec[0].Waypoint = new Waypoint();
routeSegmentsSpec[0].Waypoint.Name = "Start";
routeSegmentsSpec[0].Waypoint.Location = startLocation;
routeSegmentsSpec[1] = new SegmentSpecification();
routeSegmentsSpec[1].Waypoint = new Waypoint();
routeSegmentsSpec[1].Waypoint.Name = "End";
routeSegmentsSpec[1].Waypoint.Location = endLocation;

//Calculate the shortest route instead of the quickest
//and don't return a map view for each direction
routeSegmentsSpec[0].Options = new SegmentOptions();
routeSegmentsSpec[0].Options.Preference = SegmentPreference.Shortest;
routeSegmentsSpec[0].Options.CalculateDirectionMapView = false;

RouteSpecification routeSpec = new RouteSpecification();
routeSpec.DataSourceName = "MapPoint.NA";
routeSpec.Segments = routeSegmentsSpec;

Route myRoute;
myRoute = routeService.CalculateRoute(routeSpec);


See Also

  SegmentOptions Class   |   SegmentPreference Enumeration