Share via


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

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.