Version 3.7

Calculate directions

The Directions component provides a quick and efficient method of calculating directions between two or more locations. Similar to how the existing routeTask works, this component generates a route "finding a least-cost path between multiple services..." using a specified network service.

Directions component

This component wraps pre-built search and route functionality directly within it so all you need to do is reference the component within your application. Starting with 3.3, the routing service URL now defaults to Prior to this version 3.2, there was no default network routing service. This can be either a service hosted by your own Server or one by ArcGIS Online (such as the default.)


ArcGIS Online Network Analysis Services require an ArcGIS Online subscription. Each successful request to the service incurs service credits which are taken from your subscription. More information regarding this can be found at Accessing Services topic of the Network Analysis Services documentation.

The Directions component makes use of the Geocoder to determine the input locations. You can perform this two ways:

  1. Forward geocoding - this is handled via the standard method of typing an input location into a textbox.
  2. Reverse geocoding - this is performed after clicking on a point within the map.

Directions Input

All of this is handled by setting the Direction's locatorURL property. This points to a geocoding locator service. Please see the Geocoder topic for additional information on how this component works.

Similar to how the Geocoder component works, you can also specify input locations using map services. These services can be used on their own or in conjunction with a locator service. If wishing to work with map services, you would set them via the DirectionsGeocodeOptions.mapServices property. If you wish to only work with map services, you would set the map services as previously stated, in addition to setting the locatorURL property to null, you would also want to set the useMapServiceOnly to true. Once the input locations are determine, you can calculate the directions. This takes whatever network route service set on the Direction's URL property.


It is not possible to determine input locations by clicking on the map if only working with map services.

The advantage of using the Directions component is that it encapsulates all of this in its UI. All you need to do is provide the input locations and a URL to a route service. The resulting directions and its symbology are all handled by the component and displayed appropriately. In addition to calculating from-to directions, you can also reverse the calculated directions, display textual step-by-step directions including total distance and time, which in turn can then be printed.

Additional Information

See the Directions API sample for additional details.

In addition to the API sample, you may also want to take a look at the Directions widget in the ArcGIS Viewer for Flex application. This takes the underlying Directions component and uses it to perform similar search and route functionality within the Viewer. The source for the Viewer can be accessed from Github. Once in the application, you can find this component under src/widgets/Directions.