Skip to content

Commit d1b08b3

Browse files
committed
added readme and sc
1 parent cd61100 commit d1b08b3

File tree

4 files changed

+79
-5
lines changed

4 files changed

+79
-5
lines changed

find-route/README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
1-
# Find route
1+
# Find route
2+
3+
Display directions for a route between two points.
4+
5+
![Image of find route](find-route.png)
6+
7+
## Use case
8+
9+
Find routes with driving directions between any number of locations. You might use the ArcGIS platform to create a custom network for routing on a private roads.
10+
11+
## How to use the sample
12+
13+
For simplicity, the sample comes loaded with a start and end stop. You can tap on the floating action button to display a route between these stops. Once the route is generated, turn-by-turn directions are shown in an expandable bottom sheet. Tap on a direction to zoom to that portion of the route.
14+
15+
## How it works
16+
17+
1. Create a `RouteTask` using a URL to an online route service.
18+
2. Generate default `RouteParameters` using `routeTask.createDefaultParameters()`.
19+
3. Set `returnDirections` on the parameters to true.
20+
4. Add `Stop`s to the parameters `stops` collection for each destination.
21+
5. Solve the route using `routeTask.solveRoute(routeParameters)` to get a `RouteResult`.
22+
6. Iterate through the result's `Route`s. To display the route, create a graphic using the geometry from `route.routeGeometry`. To display directions, use `route.directionManeuvers`, and for each `DirectionManeuver`, display `DirectionManeuver.directionText`.
23+
24+
## Relevant API
25+
26+
* DirectionManeuver
27+
* Route
28+
* RouteParameters
29+
* RouteResult
30+
* RouteTask
31+
* Stop
32+
33+
## Tags
34+
35+
directions, driving, navigation, network, network analysis, route, routing, shortest path, turn-by-turn

find-route/README.metadata.json

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,42 @@
11
{
2-
}
2+
"category": "Routing and Logistics",
3+
"description": "Display directions for a route between two points.",
4+
"formal_name": "FindRoute",
5+
"ignore": false,
6+
"images": [
7+
"find-route.png"
8+
],
9+
"keywords": [
10+
"directions",
11+
"driving",
12+
"navigation",
13+
"network",
14+
"network analysis",
15+
"route",
16+
"routing",
17+
"shortest path",
18+
"turn-by-turn",
19+
"DirectionManeuver",
20+
"Route",
21+
"RouteParameters",
22+
"RouteResult",
23+
"RouteTask",
24+
"Stop"
25+
],
26+
"language": "kotlin",
27+
"redirect_from": [
28+
"/android/latest/sample-code/find-route.htm"
29+
],
30+
"relevant_apis": [
31+
"DirectionManeuver",
32+
"Route",
33+
"RouteParameters",
34+
"RouteResult",
35+
"RouteTask",
36+
"Stop"
37+
],
38+
"snippets": [
39+
"src/main/java/com/esri/arcgismaps/sample/findroute/MainActivity.kt"
40+
],
41+
"title": "Find route"
42+
}

find-route/find-route.png

217 KB
Loading

find-route/src/main/java/com/esri/arcgismaps/sample/findroute/MainActivity.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ import com.arcgismaps.mapping.view.Graphic
4747
import com.arcgismaps.mapping.view.GraphicsOverlay
4848
import com.arcgismaps.mapping.view.MapView
4949
import com.arcgismaps.tasks.networkanalysis.DirectionManeuver
50-
import com.arcgismaps.tasks.networkanalysis.Route
51-
import com.arcgismaps.tasks.networkanalysis.RouteParameters
5250
import com.arcgismaps.tasks.networkanalysis.RouteResult
5351
import com.arcgismaps.tasks.networkanalysis.RouteTask
5452
import com.arcgismaps.tasks.networkanalysis.Stop
@@ -133,6 +131,8 @@ class MainActivity : AppCompatActivity() {
133131
* and displays a graphic of the route on the map.
134132
*/
135133
private suspend fun solveRoute() {
134+
// set the applicationContext as it is required with RouteTask
135+
ArcGISEnvironment.applicationContext = this@MainActivity
136136
// create a route task instance
137137
val routeTask =
138138
RouteTask(
@@ -143,7 +143,7 @@ class MainActivity : AppCompatActivity() {
143143
mainProgressBar.visibility = View.VISIBLE
144144
routeTask.createDefaultParameters().onSuccess { routeParams ->
145145
// create stops
146-
val stops = arrayListOf(
146+
val stops = listOf(
147147
Stop(Point(-117.1508, 32.7411, SpatialReference.wgs84())),
148148
Stop(Point(-117.1555, 32.7033, SpatialReference.wgs84()))
149149
)

0 commit comments

Comments
 (0)