Using the routing service
Your routing app can do things like:
- Calculate point-to-point and multi- stop
A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. routesA route is a polyline that defines the best path between two or more points in a street network. - Optimize the results to find the shortest or the fastest route
- Find the best sequence between stops
A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. - Create routes based on the travel mode
A travel mode is the means of transportation, such as walking or driving, that defines how you can travel in a street network. (driving, cycling, walking, and so on) - Avoid restricted areas and maneuvers
- Specify time windows of arrival and departure for each stop
A stop is a single point along a route: it can be the origin, an intermediate stop, or destination. - Generate driving directions in multiple languages
What is routing?
Routing is the process of finding the best path between two or more stops
In addition to the routing described above, functionality is provided to analyze street networks. This includes the ability to create service areas
Directions
If requested, directions are returned for each route
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 route
If supported by the service
How routing works
Online and local routing both rely on a transportation network to model travel. These networks are created from features
Network Analyst services
You can create a transportation network using ArcGIS Pro.mmpk), a mobile scene package.mspk), or a mobile geodatabase
If you’d like a ready-to-use and regularly updated network dataset (and locator
Route task
A route task is a network analysis task that is executed asynchronously
The RouteTask refers to the local transportation network dataset or online service. If solves a Route using the configured RouteParameters and reports the RouteResult.
Route parameters
Route task parameters specify how a route
To initially create RouteParameters, call RouteTask.createDefaultParametersAsync() 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.
Route results
The results returned from finding a route
Examples
Find a route and directions
Use the routing service
To find a route, you need to define at least two stops to visit. The default travel mode
The result contains a set of ordered stops
81 collapsed lines
package com.esri.examples;
import com.esri.arcgisruntime.ArcGISRuntimeEnvironment;import com.esri.arcgisruntime.concurrent.ListenableFuture;import com.esri.arcgisruntime.geometry.Point;import com.esri.arcgisruntime.geometry.SpatialReferences;import com.esri.arcgisruntime.mapping.ArcGISMap;import com.esri.arcgisruntime.mapping.BasemapStyle;import com.esri.arcgisruntime.mapping.Viewpoint;import com.esri.arcgisruntime.mapping.view.Graphic;import com.esri.arcgisruntime.mapping.view.GraphicsOverlay;import com.esri.arcgisruntime.mapping.view.MapView;import com.esri.arcgisruntime.symbology.SimpleLineSymbol;import com.esri.arcgisruntime.symbology.SimpleMarkerSymbol;import com.esri.arcgisruntime.tasks.networkanalysis.Route;import com.esri.arcgisruntime.tasks.networkanalysis.RouteParameters;import com.esri.arcgisruntime.tasks.networkanalysis.RouteResult;import com.esri.arcgisruntime.tasks.networkanalysis.RouteTask;import com.esri.arcgisruntime.tasks.networkanalysis.Stop;
import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.layout.StackPane;import javafx.scene.paint.Color;import javafx.stage.Stage;
import java.util.Arrays;import java.util.List;import java.util.stream.Collectors;
public class Introduction extends Application {
private MapView mapView;
@Override public void start(Stage stage) { // JavaFX set up. stage.setTitle("Find a route and directions example"); stage.setWidth(800); stage.setHeight(700); StackPane stackPane = new StackPane(); Scene scene = new Scene(stackPane); stage.setScene(scene);
String yourAPIKey = System.getProperty("apiKey"); ArcGISRuntimeEnvironment.setApiKey(yourAPIKey);
mapView = new MapView(); stackPane.getChildren().add(mapView);
ArcGISMap map = new ArcGISMap(BasemapStyle.ARCGIS_NAVIGATION); mapView.setMap(map); mapView.setViewpoint(new Viewpoint(45.53, -122.65, 144447.638572));
SimpleMarkerSymbol originSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.WHITE, 12); originSymbol.setOutline(new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLACK, 2)); Graphic originGraphic = new Graphic(new Point(-122.690176, 45.522054, SpatialReferences.getWgs84()), originSymbol);
SimpleMarkerSymbol stopSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.Style.CIRCLE, Color.WHITE, 8); stopSymbol.setOutline(new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLACK, 2)); Graphic stopGraphic = new Graphic(new Point(-122.614995, 45.526201, SpatialReferences.getWgs84()), stopSymbol);
SimpleMarkerSymbol destinationSymbol = new SimpleMarkerSymbol((SimpleMarkerSymbol.Style.CIRCLE), Color.BLACK, 12); destinationSymbol.setOutline(new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.WHITE, 2)); Graphic destinationGraphic = new Graphic(new Point(-122.68782, 45.51238, SpatialReferences.getWgs84()), destinationSymbol);
Graphic routeGraphic = new Graphic(); routeGraphic.setSymbol(new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLUE, 4));
GraphicsOverlay graphicsOverlay = new GraphicsOverlay(); mapView.getGraphicsOverlays().add(graphicsOverlay);
graphicsOverlay.getGraphics().addAll(Arrays.asList(routeGraphic, originGraphic, stopGraphic, destinationGraphic));
List<Stop> stops = graphicsOverlay.getGraphics() .stream() .filter(graphic -> graphic.getGeometry() != null) .map(graphic -> new Stop((Point) graphic.getGeometry())) .collect(Collectors.toList());
RouteTask routeTask = new RouteTask("https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World");
ListenableFuture<RouteParameters> routeParametersFuture = routeTask.createDefaultParametersAsync();
routeParametersFuture.addDoneListener(() -> { try { RouteParameters routeParameters = routeParametersFuture.get(); routeParameters.setStops(stops);
routeParameters.setReturnDirections(true); routeParameters.setDirectionsLanguage("es");
ListenableFuture<RouteResult> routeResultFuture = routeTask.solveRouteAsync(routeParameters);
routeResultFuture.addDoneListener(() -> { try { RouteResult routeResult = routeResultFuture.get(); Route route = routeResult.getRoutes().getFirst(); routeGraphic.setGeometry(route.getRouteGeometry());
route.getDirectionManeuvers().forEach(step -> System.out.println(step.getDirectionText())); } catch (Exception e) { e.printStackTrace(); } }); } catch (Exception e) { e.printStackTrace(); } });14 collapsed lines
}
public static void main(String[] args) { Application.launch(args); }
@Override public void stop() { if (mapView != null) { mapView.dispose(); } }}Use API key access tokens
An API key access tokenApiKeyResource.
Tutorials
Samples
Find route
Offline routing
Route around barriers
Display device location with autopan modes