Using the routing serviceA routing service is a service that uses network analysis and streets data to calculate the most effective path and turn-by-turn directions on a street network, optimize fleet routing and deliveries, find the closest facilities, calculate service areas, and more. It is hosted by Esri as the ArcGIS Routing service and can also be hosted in ArcGIS Enterprise. Learn more , your own route servicesA service, also known as an ArcGIS service, is software that supports an ArcGIS REST API and provides geospatial functionality or data. A service can be hosted by Esri or in ArcGIS Enterprise. Learn more , or a route dataset stored on the deviceA device is nearly any kind of computer, including desktops, laptops, mobile phones, and tablets. Learn more , you can find routesA route is a polyline that defines the best path between two or more points in a street network. Learn more , directions, and perform advanced analyses on street networks. You can solve network problems such as finding the closest emergency vehicle or facility, identifying a service areaA service area is a polygon representing the distance that can be reached within a specified length of time while traveling in a street network. Learn more around a locationA location is a position or region (point, line, or polygon) on the earth's surface. Learn more , or servicing a set of orders with a fleet of vehicles.

Your routing app can do things like:

  • Calculate point-to-point and multi-stopA stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more routesA route is a polyline that defines the best path between two or more points in a street network. Learn more
  • Optimize the results to find the shortest or the fastest route
  • Find the best sequence between stopsA stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more
  • Create routes based on the travel modeA travel mode is the means of transportation, such as walking or driving, that defines how you can travel in a street network. Learn more (driving, cycling, walking, and so on)
  • Avoid restricted areas and maneuvers
  • Specify time windows of arrival and departure for each stopA stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more
  • Generate driving directions in multiple languages

What is routing?

Routing is the process of finding the best path between two or more stopsA stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more in a street network. A common use case is to find a routeA route is a polyline that defines the best path between two or more points in a street network. Learn more between two stops, from an originAn origin is a point that defines the start of a route. Learn more to a destinationA destination is a point that defines the final stop in a route. Learn more . Routing takes into consideration many different attributesAttributes are fields and values for a single feature or non-spatial record. They are typically stored in a database or service such as a feature service. Learn more in the street network such as speed limit, number of lanes, and time of day. Routing can also incorporate real-time data such as road conditions, accidents, street closures, and other restrictions to travel.

In addition to the routing described above, functionality is provided to analyze street networks. This includes the ability to create service areasA service area is a polygon representing the distance that can be reached within a specified length of time while traveling in a street network. Learn more (to find customers within a certain drive time, for example) or locate a closest facility (nearest hospital to an accident, for example).

Directions

If requested, directions are returned for each routeA route is a polyline that defines the best path between two or more points in a street network. Learn more in the results. Directions provide specific instructions for traveling the route. These are often referred to as “driving directions”, but depending on the travel modeA travel mode is the means of transportation, such as walking or driving, that defines how you can travel in a street network. Learn more , could describe walking or cycling to the destinationA destination is a point that defines the final stop in a route. Learn more . Depending on the servicesA service, also known as an ArcGIS service, is software that supports an ArcGIS REST API and provides geospatial functionality or data. A service can be hosted by Esri or in ArcGIS Enterprise. Learn more configuration, directions can be returned in more than one language. Supported languages for a service are available in the service metadata.

Directions are composed of maneuvers. Each maneuver contains properties such as the direction text, which contains instructions that describe travel through a section of a routeA route is a polyline that defines the best path between two or more points in a street network. Learn more . A direction maneuver is further broken down into maneuver messages that give details about a specific maneuver.

If supported by the serviceA service, also known as an ArcGIS service, is software that supports an ArcGIS REST API and provides geospatial functionality or data. A service can be hosted by Esri or in ArcGIS Enterprise. Learn more , direction maneuver’s can include from level and to level values to define things like floor levels inside a building. For example, a user may want to see just one level of a walking routeA route is a polyline that defines the best path between two or more points in a street network. Learn more that spans multiple floors.

The navigation API allows you to further enhance the routing experience using the current device locationA location is a position or region (point, line, or polygon) on the earth's surface. Learn more to track progress and provide navigation instructions (maneuvers) as the user travels the routeA route is a polyline that defines the best path between two or more points in a street network. Learn more . You can integrate driving directions with your device’s text-to-speech capability and automatically recalculate a new route when the user leaves the current one.

The route tracker object provides the following functionality using the current device locationA location is a position or region (point, line, or polygon) on the earth's surface. Learn more and an appropriate routeA route is a polyline that defines the best path between two or more points in a street network. Learn more result:

  • Progress information relative to the next stopA stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more , to the next maneuver, or along the entire route
  • Guidance for navigation as it’s needed (when approaching a maneuver, for example)
  • Automatic recalculation of a routeA route is a polyline that defines the best path between two or more points in a street network. Learn more if the device locationA location is a position or region (point, line, or polygon) on the earth's surface. Learn more goes off route

How routing works

Online and local routing both rely on a transportation network to model travel. These networks are created from featuresA feature is a single record, also known as a row, that represents a real-world entity. It typically contains a geometry (point, multipoint, polyline, or polygon) and attributes but it can also contain just attributes. Learn more (lines and points) that represent roads, bridges, tunnels, bike paths, train tracks, and other entities in the network. The geometric intersections of features help to define connectivity between the network entities they represent. The connectivity of the transportation network, along with resistance to travel (speed limit, for example) and other network properties, is analyzed to solve routing problems.

Network Analyst servicesA service, also known as an ArcGIS service, is software that supports an ArcGIS REST API and provides geospatial functionality or data. A service can be hosted by Esri or in ArcGIS Enterprise. Learn more are hosted in ArcGIS or can be published on your own ArcGIS servers. These services provide a REST API for clients such as mobile and Web applications. For more information about publishing routing services with ArcGIS EnterpriseArcGIS Enterprise is a GIS mapping, analytics, data hosting, and content management product that can be hosted on-premise or in a cloud infrastructure. It includes software, applications, tools, APIs, and services for users and developers. Learn more , see Publish routing services.

You can create a transportation network using ArcGIS ProArcGIS Pro is a professional desktop GIS application that can explore, visualize, analyze, and manage 2D and 3D data. Learn more and deploy it to your device using either a mobile map packageA mobile map package (MMPK) is a standalone file that contains one or more map definitions, including the basemap layers, data layers, layer styles, and pop-up styles for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more file (.mmpk), a mobile scene packageA mobile scene package (MSPK) is a standalone file that contains one or more scene definitions, including the basemap layers, elevation layers, data layers, layer styles, and pop-up styles for use in offline applications built with ArcGIS Maps SDKs for Native Apps. Learn more file (.mspk), or a mobile geodatabaseA mobile geodatabase (.geodatabase) is a spatial data storage format in a single file on disk that can store, query, and manage spatial and nonspatial data. In applications built with the ArcGIS Maps SDKs for Native Apps, mobile geodatabases can be used in offline workflows when taking maps and features offline from services or in desktop-based scenarios as standalone mobile geodatabases from ArcGIS Pro. Learn more file. The code to work with a local transportation network (stored directly on the deviceA device is nearly any kind of computer, including desktops, laptops, mobile phones, and tablets. Learn more ) is identical to the code for using a routing serviceA service, also known as an ArcGIS service, is software that supports an ArcGIS REST API and provides geospatial functionality or data. A service can be hosted by Esri or in ArcGIS Enterprise. Learn more .

If you’d like a ready-to-use and regularly updated network dataset (and locatorA locator is an ArcGIS dataset that stores address information and the rules for translating descriptions of places (such as street addresses or place names) into spatial data that can be displayed on a map. Learn more ) for your area of interest, you can license StreetMap Premium data (in mobile map package format). For details, see Add StreetMap Premium data.

Route task

A route task is a network analysis task that is executed asynchronouslyAsynchronous is a style of programming that involves executing multiple tasks simultaneously rather than sequentially. Learn more . It returns results with details about a routeA route is a polyline that defines the best path between two or more points in a street network. Learn more that visits two or more stopsA stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more (locationsA location is a position or region (point, line, or polygon) on the earth's surface. Learn more ) within a transportation network. This operation is sometimes referred to as solving a routeA route is a polyline that defines the best path between two or more points in a street network. Learn more .

The RouteTask refers to the local transportation network dataset or online service. It solves a Route using the configured RouteParameters and reports the RouteResult.

// Create a route task against the online world route service.
routeTask = RouteTask.withUri(routeServiceUri);

    Route parameters

    Route task parameters specify how a routeA route is a polyline that defines the best path between two or more points in a street network. Learn more should be found. There are many parameters that let you customize how the route is determined. Parameters include stopsA stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more and barriersA barrier is a geometric feature that alters which streets a route can traverse in a street network. Learn more . Other parameters include travel modeA travel mode is the means of transportation, such as walking or driving, that defines how you can travel in a street network. Learn more , whether stops map be reordered to find an optimized routeAn optimized route is the lowest cost path that visits all stops specified by the user in the most efficient order, regardless of the order in which they are provided. Learn more , the units to be used in the turn-by-turn directions (miles or kilometers, for example), and so on.

    To initially create RouteParameters, call RouteTask.createDefaultParameters() to retrieve the default routing parameters defined for the service. You can then change individual route parameters as needed before executing the RouteTask. The service’s default parameters typically support the most common use case anticipated for that service. Different services can have different defaults.

    // Create the route service's default parameters and configure them to return stops, routes, and directions in Spanish.
    routeParameters = await routeTask.createDefaultParameters()
    ..returnStops = true
    ..returnRoutes = true
    ..returnDirections = true
    ..directionsLanguage = 'es';
    // Build stops in travel order.
    _stops
    ..clear()
    ..addAll([
    Stop(originPoint)..name = 'Origin',
    Stop(intermediateStopPoint)..name = 'Intermediate',
    Stop(destinationPoint)..name = 'Destination',
    ]);

      Route results

      The results returned from finding a routeA route is a polyline that defines the best path between two or more points in a street network. Learn more contain a collection of routes. Each route is represented by a polylineA polyline is a type of geometry containing ordered point coordinates and a spatial reference. Learn more geometry and has information such as its total length and travel time. Depending on how you configured your route parameters, the results may also contain barriersA barrier is a geometric feature that alters which streets a route can traverse in a street network. Learn more , stopsA stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more , and driving directions. Typically, the routeA route is a polyline that defines the best path between two or more points in a street network. Learn more , stops, and barriers are displayed as graphicsA graphic is a visual element composed of a geometry, symbol, and attributes that is displayed on a map or scene. Learn more in the mapA map is a collection of layers that are displayed in 2D. It is typically composed of a basemap layer and data layers. Learn more . Directions can be shown in a list or other UI element in the app.

      // Solve the route using the route parameters.
      final routeResult = await routeTask.solveRoute(routeParameters);
      if (routeResult.routes.isEmpty) {
      setState(() => _directions = []);
      _routeOverlay.graphics.clear();
      return;
      }
      final route = routeResult.routes.first;
      _routeOverlay.graphics
      ..clear()
      ..add(
      Graphic(
      geometry: route.routeGeometry,
      symbol: SimpleLineSymbol(color: Colors.blue, width: 4),
      ),
      );
      setState(() => _directions = route.directionManeuvers);
      } on ArcGISException {
      _routeOverlay.graphics.clear();
      setState(() => _directions = []);
      }

        Examples

        Find a route and directions

        Use the routing serviceA routing service is a service that uses network analysis and streets data to calculate the most effective path and turn-by-turn directions on a street network, optimize fleet routing and deliveries, find the closest facilities, calculate service areas, and more. It is hosted by Esri as the ArcGIS Routing service and can also be hosted in ArcGIS Enterprise. Learn more to find a routeA route is a polyline that defines the best path between two or more points in a street network. Learn more between a set of stopsA stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more . The result will account for current traffic conditions and provide driving directions in Spanish.

        To find a route, you need to define at least two stops to visit. The default travel modeA travel mode is the means of transportation, such as walking or driving, that defines how you can travel in a street network. Learn more is driving, but you can use walk or trucking travel modes as well. It is always good to provide the start time to get the best results (to consider the appropriate traffic conditions, for example). In this example, the start time is set with the current time which indicates to the service that the route should use the current traffic conditions. The directions language is set to “es” to generate driving directions in Spanish.

        The result contains a set of ordered stopsA stop is a single point along a route: it can be the origin, an intermediate stop, or destination. Learn more to visit, the route segments, and turn-by-turn text directions.

        // Create a route task against the online world route service.
        routeTask = RouteTask.withUri(routeServiceUri);
        // Create the route service's default parameters and configure them to return stops, routes, and directions in Spanish.
        routeParameters = await routeTask.createDefaultParameters()
        ..returnStops = true
        ..returnRoutes = true
        ..returnDirections = true
        ..directionsLanguage = 'es';
        // Create the three predefined stop points.
        final originPoint = ArcGISPoint(
        x: -122.690,
        y: 45.522,
        spatialReference: SpatialReference.wgs84,
        );
        final intermediateStopPoint = ArcGISPoint(
        x: -122.615,
        y: 45.526,
        spatialReference: SpatialReference.wgs84,
        );
        final destinationPoint = ArcGISPoint(
        x: -122.688,
        y: 45.512,
        spatialReference: SpatialReference.wgs84,
        );
        // Build stops in travel order.
        _stops
        ..clear()
        ..addAll([
        Stop(originPoint)..name = 'Origin',
        Stop(intermediateStopPoint)..name = 'Intermediate',
        Stop(destinationPoint)..name = 'Destination',
        ]);
        // Show stop graphics on the map.
        _stopsOverlay.graphics
        ..clear()
        ..addAll([
        Graphic(
        geometry: originPoint,
        symbol: SimpleMarkerSymbol(
        style: SimpleMarkerSymbolStyle.circle,
        color: Colors.green,
        size: 10,
        ),
        ),
        Graphic(
        geometry: intermediateStopPoint,
        symbol: SimpleMarkerSymbol(
        style: SimpleMarkerSymbolStyle.circle,
        color: Colors.orange,
        size: 10,
        ),
        ),
        Graphic(
        geometry: destinationPoint,
        symbol: SimpleMarkerSymbol(
        style: SimpleMarkerSymbolStyle.circle,
        color: Colors.red,
        size: 10,
        ),
        ),
        ]);
        await _zoomToStopsExtent();
        await _solveRoute();
        }
        Future<void> _zoomToStopsExtent() async {
        if (_stopsOverlay.graphics.isEmpty) return;
        // Build a combined extent for all stop graphics and add padding for context.
        final envelopeBuilder = EnvelopeBuilder(
        spatialReference: SpatialReference.wgs84,
        );
        for (final graphic in _stopsOverlay.graphics) {
        envelopeBuilder.unionWithEnvelope(graphic.geometry!.extent);
        }
        envelopeBuilder.expandBy(1.5);
        await _mapViewController.setViewpointAnimated(
        Viewpoint.fromTargetExtent(envelopeBuilder.extent),
        );
        }
        Future<void> _solveRoute() async {
        try {
        routeParameters
        ..clearStops()
        ..setStops(_stops);
        // Solve the route using the route parameters.
        final routeResult = await routeTask.solveRoute(routeParameters);
        if (routeResult.routes.isEmpty) {
        setState(() => _directions = []);
        _routeOverlay.graphics.clear();
        return;
        }
        final route = routeResult.routes.first;
        _routeOverlay.graphics
        ..clear()
        ..add(
        Graphic(
        geometry: route.routeGeometry,
        symbol: SimpleLineSymbol(color: Colors.blue, width: 4),
        ),
        );
        setState(() => _directions = route.directionManeuvers);
        } on ArcGISException {
        _routeOverlay.graphics.clear();
        setState(() => _directions = []);
        }
        }

          Use API keys

          Samples

          Services