View on GitHub Sample viewer app

Solve a route on-the-fly using offline data.

Image of find route in transport network

Use case

You can use an offline network to enable routing in disconnected scenarios. For example, you could provide offline location capabilities to field workers repairing critical infrastructure in a disaster when network availability is limited.

How to use the sample

Tap once near a road to add a stop to the map. A number graphic will show its order in the route. After adding at least 2 stops, a route will display. Choose “Fastest” or “Shortest” from the switch at the top of the screen to control how the route is optimized. The route will update on-the-fly while moving stops. The green box marks the boundary of the routable area provided by the offline data.

How it works

  1. Create the map’s Basemap from a local tile package using a TileCache and ArcGISTiledLayer.
  2. Create a RouteTask with an offline locator geodatabase.
  3. Get the RouteParameters using routeTask.createDefaultParameters().
  4. Create Stops and add them to the route task’s parameters using RouteParameters.setStops(...).
  5. Solve the Route using routeTask.solveRoute(routeParameters).
  6. Create a graphic with the route’s geometry and a SimpleLineSymbol and display it on another GraphicsOverlay.

Relevant API

  • RouteParameters
  • RouteResult
  • RouteTask
  • Stop
  • TravelMode

About the data

This sample uses a pre-packaged sample dataset consisting of a geodatabase with a San Diego road routing network and a tile package with a streets basemap.

Tags

connectivity, disconnected, fastest, locator, navigation, network analysis, offline, routing, shortest, turn-by-turn

Sample Code

DownloadActivity.kt DownloadActivity.kt MainActivity.kt
/* Copyright 2023 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.esri.arcgismaps.sample.findrouteintransportnetwork
import android.content.Intent
import android.os.Bundle
import com.esri.arcgismaps.sample.sampleslib.DownloaderActivity
class DownloadActivity : DownloaderActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
downloadAndStartSample(
Intent(this, MainActivity::class.java),
// get the app name of the sample
getString(R.string.find_route_in_transport_network_app_name),
listOf(
//A zip file containing an offline routing network and .tpkx basemap
"https://arcgisruntime.maps.arcgis.com/home/item.html?id=df193653ed39449195af0c9725701dca"
)
)
}
}