Optimize method
Reorders the intermediate stops on a route so that the travel time between the start and end points is the most efficient; similar to clicking Optimize Stops on the Route menu.
Applies to
Collections: Waypoints
Syntax
object.Optimize
Part | Description |
---|---|
object | Required. An expression that returns a Waypoints collection. |
Remarks
The RouteAfterOptimize event of the Map or MappointControl object occurs after the stops on the route have been optimized.
After stops are optimized, the route no longer exists on the map. Be sure to use the Calculate method on the Route object.
For more information about optimizing the stops on a route, see the Optimize the stops on your route procedural topic.
Example
Sub OptimizeRoute()
Dim objApp As New MapPoint.Application
Dim objMap As MapPoint.Map
Dim objRoute As MapPoint.Route
'Set up the application
Set objMap = objApp.ActiveMap
Set objRoute = objMap.ActiveRoute
objApp.Visible = True
objApp.UserControl = True
'Add route stops and calculate route
With objRoute.Waypoints
.Add objMap.FindResults("Seattle, WA").Item(1)
.Add objMap.FindResults("Redmond, WA").Item(1)
.Add objMap.FindResults("Tacoma, WA").Item(1)
.Add objMap.FindResults("Bellevue, WA").Item(1)
End With
objRoute.Calculate
'Optimize the route
objRoute.Waypoints.Optimize
End Sub
Note This sample code is specifically for use in MapPoint North America; it is for illustration purposes only.