Overview

You will learn: how to get a route to the closest destination from a set of possible destinations with the ArcGIS Transportation Routing and Network Analytics Services.

The ArcGIS Transportation Routing and Network Analytics Services can find routes, get driving directions, calculate drive times, and solve complicated multiple vehicle routing problems(VRP). If you want to create an application that can create a route to the nearest of several possible destinations, you can use the ArcGIS REST API and the solveClosestFacility operation. All you need to do is pass in the location (incident) and the possible facilities that can provide service, and the service will return the ordered routes that can be reached including directions. You can also add point, line, and polygon barriers to create routes around restricted areas or even add time restrictions that take traffic into consideration. Once you have the results you can add the routes to a map or integrate them further into your application. To learn more about the capabilities of the directions and routing service, please visit the documentation.

In this lab you will use the ArcGIS REST API to access the ArcGIS Transportation Routing and Network Analytics Services to determine which of three trailheads is the closest to a location and get a route and directions between the two points.

Before you begin

Install Postman to execute HTTP requests. Go to this lab if you need an access token.

Steps

Create a request to access the directions service

  1. Open Postman and click [+] in the tab bar to create a new request.

  2. In the new tab, set the following:

    • HTTP Method: POST
    • Request URL: https://route.arcgis.com/arcgis/rest/services/World/ClosestFacility/NAServer/ClosestFacility_World/solveClosestFacility

Add parameters to define the incident and the service locations

  1. Click on Body and add the following Key/Value pairs:

    • f: json
    • token: Go to this lab if you need an access token.
    • returnDirections: true
    • returnCFRoutes: true
  2. Add the following parameter to set the incident location (destination) for the route:

    • incidents:
      {
        "features":  [
            {
            "geometry": {
              "x":-118.257363,
              "y":34.076763,
              "spatialReference": {
                "wkid": "4326"
              }
            },
            "attributes": {
              "Name": "Echo Park Ave & W Sunset Blvd, Los Angeles, California, 90026"
            }
          }
        ]
      }
      
  3. Add the following parameter to set the possible facility locations for the route:

    • facilities:
      {
        "features":  [
            {
            "geometry": {
              "x": -118.3417932,
              "y": 34.00451385,
              "spatialReference": {
                "wkid": "4326"
              }
            },
            "attributes": {
              "Name": "Stocker Corridor"
            }
          },
          {
            "geometry": {
              "x": -118.08788,
              "y": 34.01752,
              "spatialReference": {
                "wkid": "4326"
              }
            },
            "attributes": {
              "Name": "Rio Hondo River Trail"
            }
          },
          {
            "geometry": {
              "x": -118.20327,
              "y": 34.19382,
              "spatialReference": {
                "wkid": "4326"
              }
            },
            "attributes": {
              "Name": "Flint Wash Trail"
            }
          }
        ]
      }
      

Execute the request to create the routes and directions

  1. Click Send to run the request.

  2. In the response window, change the view to JSON and it should look something like this:

    {
      "messages":[
    
      ],
      "routes":{
        "fieldAliases":{
          "ObjectID":"ObjectID",
          "FacilityID":"FacilityID",
          "FacilityRank":"FacilityRank",
          "Name":"Name",
          "IncidentCurbApproach":"IncidentCurbApproach",
          "FacilityCurbApproach":"FacilityCurbApproach",
          "IncidentID":"IncidentID",
          "Total_TravelTime":"Total_TravelTime",
          "Total_Kilometers":"Total_Kilometers",
          "Total_Miles":"Total_Miles",
          "Shape_Length":"Shape_Length"
        },
        "geometryType":"esriGeometryPolyline",
        "spatialReference":{
          "wkid":4326,
          "latestWkid":4326
        },
        "features":[
          {
            "attributes":{
              "ObjectID":1,
              "FacilityID":3,
              "FacilityRank":1,
              "Name":"Echo Park Ave & W Sunset Blvd, Los Angeles, California, 90026 - Flint Wash Trail",
              "IncidentCurbApproach":1,
              "FacilityCurbApproach":2,
              "IncidentID":1,
              "Total_TravelTime":18.25230158430363,
              "Total_Kilometers":18.721093443754757,
              "Total_Miles":11.632748153132429,
              "Shape_Length":0.17712577347701752
            },
            "geometry":{
              "paths":[
                [
                  [
                    -118.25736393499994,
                    34.076763573000051
                  ],
                  [
                    -118.25735999999995,
                    34.076770000000067
                  ],
                  [
                    -118.25779999999997,
                    34.076950000000068
                  ],
                  [
                    -118.25799999999998,
                    34.077040000000068
                  ],
                  [
                    -118.25873999999999,
                    34.077360000000056
                  ],
                  [
                    -118.25900999999999,
                    34.077480000000037
                  ],
                  [
                    -118.25941999999998,
                    34.077660000000037
                  ],
                  [
                    -118.25913999999995,
                    34.078130000000044
                  ],
                  [
                    -118.25897999999995,
                    34.078380000000038
                  ],
                  [
                    -118.25864999999999,
                    34.078920000000039
                  ],
                  [
                    -118.25944999999996,
                    34.079390000000046
                  ],
                  [
                    -118.25963999999999,
                    34.079500000000053
                  ],
                  [
                    -118.26009999999997,
                    34.07973000000004
                  ],
                  [
                    -118.26000999999997,
                    34.081860000000063
                  ],
                  [
                    -118.25996999999995,
                    34.082870000000071
                  ],
                  [
                    -118.25995999999998,
                    34.08313000000004
                  ],
                  [
                    -118.25992999999994,
                    34.083440000000053
                  ],
                  [
                    -118.25985999999995,
                    34.085020000000043
                  ],
                  [
                    -118.25983999999994,
                    34.085460000000069
                  ],
                  [
                    -118.25990999999999,
                    34.085780000000057
                  ],
                  [
                    -118.25986999999998,
                    34.086080000000038
                  ],
                  [
                    -118.25980999999996,
                    34.086580000000026
                  ],
                  [
                    -118.25967999999995,
                    34.087350000000072
                  ],
                  [
                    -118.25961999999998,
                    34.087700000000041
                  ],
                  [
                    -118.25951999999995,
                    34.088200000000029
                  ],
                  [
                    -118.25937999999996,
                    34.088940000000036
                  ],
                  [
                    -118.25933999999995,
                    34.089140000000043
                  ],
                  [
                    -118.25926999999996,
                    34.089510000000075
                  ],
                  [
                    -118.25909999999999,
                    34.089970000000051
                  ],
                  [
                    -118.25890999999996,
                    34.090370000000064
                  ],
                  [
                    -118.25885999999997,
                    34.090450000000033
                  ],
                  [
                    -118.25865999999996,
                    34.090800000000058
                  ],
                  [
                    -118.25857999999994,
                    34.090940000000046
                  ],
                  [
                    -118.25739999999996,
                    34.092130000000054
                  ],
                  [
                    -118.25622999999996,
                    34.09328000000005
                  ],
                  [
                    -118.25591999999995,
                    34.093570000000057
                  ],
                  [
                    -118.25565999999998,
                    34.093800000000044
                  ],
                  [
                    -118.25554999999997,
                    34.093900000000076
                  ],
                  [
                    -118.25544999999994,
                    34.094000000000051
                  ],
                  [
                    -118.25451999999996,
                    34.095010000000059
                  ],
                  [
                    -118.25433999999996,
                    34.095250000000078
                  ],
                  [
                    -118.25391999999999,
                    34.095800000000054
                  ],
                  [
                    -118.25309999999996,
                    34.096930000000043
                  ],
                  [
                    -118.25249999999994,
                    34.097760000000051
                  ],
                  [
                    -118.25183999999996,
                    34.098640000000046
                  ],
                  [
                    -118.25164999999998,
                    34.098920000000078
                  ],
                  [
                    -118.25055999999995,
                    34.100600000000043
                  ],
                  [
                    -118.24998999999997,
                    34.102070000000026
                  ],
                  [
                    -118.24995999999999,
                    34.102190000000064
                  ],
                  [
                    -118.24991999999997,
                    34.102360000000033
                  ],
                  [
                    -118.24973999999997,
                    34.103800000000035
                  ],
                  [
                    -118.24967999999996,
                    34.105260000000044
                  ],
                  [
                    -118.24961999999999,
                    34.106980000000078
                  ],
                  [
                    -118.24941999999999,
                    34.108840000000043
                  ],
                  [
                    -118.24932999999999,
                    34.109060000000056
                  ],
                  [
                    -118.24846999999994,
                    34.110340000000065
                  ],
                  [
                    -118.24810999999994,
                    34.110690000000034
                  ],
                  [
                    -118.24743999999998,
                    34.111150000000066
                  ],
                  [
                    -118.24668999999994,
                    34.111620000000073
                  ],
                  [
                    -118.24642999999998,
                    34.111780000000067
                  ],
                  [
                    -118.24615999999997,
                    34.111950000000036
                  ],
                  [
                    -118.24415999999997,
                    34.113200000000063
                  ],
                  [
                    -118.24140999999997,
                    34.11474000000004
                  ],
                  [
                    -118.24033999999995,
                    34.115180000000066
                  ],
                  [
                    -118.23880999999994,
                    34.115890000000036
                  ],
                  [
                    -118.23758999999995,
                    34.116550000000075
                  ],
                  [
                    -118.23491999999999,
                    34.117880000000071
                  ],
                  [
                    -118.23308999999995,
                    34.118800000000078
                  ],
                  [
                    -118.23219999999998,
                    34.119270000000029
                  ],
                  [
                    -118.23094999999995,
                    34.12008000000003
                  ],
                  [
                    -118.22956999999997,
                    34.121430000000032
                  ],
                  [
                    -118.22896999999995,
                    34.122330000000034
                  ],
                  [
                    -118.22844999999995,
                    34.123480000000029
                  ],
                  [
                    -118.22811999999999,
                    34.125120000000038
                  ],
                  [
                    -118.22810999999996,
                    34.125670000000071
                  ],
                  [
                    -118.22812999999996,
                    34.126030000000071
                  ],
                  [
                    -118.22870999999998,
                    34.129310000000032
                  ],
                  [
                    -118.22888999999998,
                    34.130340000000047
                  ],
                  [
                    -118.22903999999994,
                    34.131110000000035
                  ],
                  [
                    -118.22936999999996,
                    34.13310000000007
                  ],
                  [
                    -118.22939999999994,
                    34.134780000000035
                  ],
                  [
                    -118.22930999999994,
                    34.13557000000003
                  ],
                  [
                    -118.22922999999997,
                    34.136010000000056
                  ],
                  [
                    -118.22896999999995,
                    34.136970000000076
                  ],
                  [
                    -118.22859999999997,
                    34.138230000000078
                  ],
                  [
                    -118.22843999999998,
                    34.138780000000054
                  ],
                  [
                    -118.22819999999996,
                    34.139640000000043
                  ],
                  [
                    -118.22809999999998,
                    34.14002000000005
                  ],
                  [
                    -118.22783999999996,
                    34.140860000000032
                  ],
                  [
                    -118.22737999999998,
                    34.142510000000073
                  ],
                  [
                    -118.22730999999999,
                    34.142770000000041
                  ],
                  [
                    -118.22724999999997,
                    34.142950000000042
                  ],
                  [
                    -118.22712999999999,
                    34.143350000000055
                  ],
                  [
                    -118.22686999999996,
                    34.144280000000037
                  ],
                  [
                    -118.22671999999994,
                    34.144790000000057
                  ],
                  [
                    -118.22624999999999,
                    34.146360000000072
                  ],
                  [
                    -118.22602999999998,
                    34.147110000000055
                  ],
                  [
                    -118.22593999999998,
                    34.147460000000024
                  ],
                  [
                    -118.22536999999994,
                    34.149450000000058
                  ],
                  [
                    -118.22414999999995,
                    34.153750000000059
                  ],
                  [
                    -118.22408999999999,
                    34.155390000000068
                  ],
                  [
                    -118.22411999999997,
                    34.155670000000043
                  ],
                  [
                    -118.22435999999999,
                    34.156810000000064
                  ],
                  [
                    -118.22446999999994,
                    34.157180000000039
                  ],
                  [
                    -118.22456999999997,
                    34.157520000000034
                  ],
                  [
                    -118.22476999999998,
                    34.158100000000047
                  ],
                  [
                    -118.22541999999999,
                    34.16041000000007
                  ],
                  [
                    -118.22538999999995,
                    34.16217000000006
                  ],
                  [
                    -118.22478999999998,
                    34.164290000000051
                  ],
                  [
                    -118.22362999999996,
                    34.167950000000076
                  ],
                  [
                    -118.22340999999994,
                    34.168640000000039
                  ],
                  [
                    -118.22239999999999,
                    34.171820000000025
                  ],
                  [
                    -118.22133999999994,
                    34.175180000000069
                  ],
                  [
                    -118.22004999999996,
                    34.179190000000062
                  ],
                  [
                    -118.21775999999994,
                    34.183700000000044
                  ],
                  [
                    -118.21735999999999,
                    34.185800000000029
                  ],
                  [
                    -118.21742999999998,
                    34.18679000000003
                  ],
                  [
                    -118.21773999999999,
                    34.188020000000051
                  ],
                  [
                    -118.21960999999999,
                    34.192110000000071
                  ],
                  [
                    -118.22013999999996,
                    34.194450000000074
                  ],
                  [
                    -118.22002999999995,
                    34.196610000000078
                  ],
                  [
                    -118.21988999999996,
                    34.197280000000035
                  ],
                  [
                    -118.21968999999996,
                    34.198190000000068
                  ],
                  [
                    -118.21956999999998,
                    34.198710000000062
                  ],
                  [
                    -118.21942999999999,
                    34.199250000000063
                  ],
                  [
                    -118.21923999999996,
                    34.199840000000052
                  ],
                  [
                    -118.21888999999999,
                    34.200900000000047
                  ],
                  [
                    -118.21846999999997,
                    34.202670000000069
                  ],
                  [
                    -118.21802999999994,
                    34.203830000000039
                  ],
                  [
                    -118.21773999999999,
                    34.204560000000072
                  ],
                  [
                    -118.21753999999999,
                    34.204830000000072
                  ],
                  [
                    -118.21713999999997,
                    34.205550000000073
                  ],
                  [
                    -118.21598999999998,
                    34.205630000000042
                  ],
                  [
                    -118.21551999999997,
                    34.205650000000048
                  ],
                  [
                    -118.21526999999998,
                    34.20566000000008
                  ],
                  [
                    -118.21497999999997,
                    34.205670000000055
                  ],
                  [
                    -118.21479999999997,
                    34.205670000000055
                  ],
                  [
                    -118.21465999999998,
                    34.205670000000055
                  ],
                  [
                    -118.21441999999996,
                    34.205670000000055
                  ],
                  [
                    -118.21412999999995,
                    34.205670000000055
                  ],
                  [
                    -118.21297999999996,
                    34.205680000000029
                  ],
                  [
                    -118.21246999999994,
                    34.205670000000055
                  ],
                  [
                    -118.21212999999995,
                    34.205670000000055
                  ],
                  [
                    -118.21156999999999,
                    34.20566000000008
                  ],
                  [
                    -118.21158999999994,
                    34.205040000000054
                  ],
                  [
                    -118.21151999999995,
                    34.204050000000052
                  ],
                  [
                    -118.21047999999996,
                    34.203530000000057
                  ],
                  [
                    -118.20896999999997,
                    34.20288000000005
                  ],
                  [
                    -118.20813999999996,
                    34.202540000000056
                  ],
                  [
                    -118.20730999999995,
                    34.202020000000061
                  ],
                  [
                    -118.20681999999999,
                    34.201400000000035
                  ],
                  [
                    -118.20581999999996,
                    34.200120000000027
                  ],
                  [
                    -118.20562999999999,
                    34.199880000000064
                  ],
                  [
                    -118.20542999999998,
                    34.199610000000064
                  ],
                  [
                    -118.20501999999999,
                    34.199260000000038
                  ],
                  [
                    -118.20389999999998,
                    34.198950000000025
                  ],
                  [
                    -118.20342999999997,
                    34.198830000000044
                  ],
                  [
                    -118.20302999999996,
                    34.198730000000069
                  ],
                  [
                    -118.20268999999996,
                    34.198650000000043
                  ],
                  [
                    -118.20160999999996,
                    34.198550000000068
                  ],
                  [
                    -118.20106999999996,
                    34.198410000000024
                  ],
                  [
                    -118.20106999999996,
                    34.198200000000043
                  ],
                  [
                    -118.20099999999996,
                    34.197940000000074
                  ],
                  [
                    -118.20021999999994,
                    34.197100000000034
                  ],
                  [
                    -118.20019999999994,
                    34.19640000000004
                  ],
                  [
                    -118.20104999999995,
                    34.196420000000046
                  ],
                  [
                    -118.20169999999996,
                    34.196060000000045
                  ],
                  [
                    -118.20253999999994,
                    34.196020000000033
                  ],
                  [
                    -118.20276999999999,
                    34.19587000000007
                  ],
                  [
                    -118.20280999999994,
                    34.195650000000057
                  ],
                  [
                    -118.20229999999998,
                    34.194850000000031
                  ],
                  [
                    -118.20210999999995,
                    34.194640000000049
                  ],
                  [
                    -118.20219999999995,
                    34.194450000000074
                  ],
                  [
                    -118.20305999999999,
                    34.194270000000074
                  ],
                  [
                    -118.20332258899998,
                    34.193816244000061
                  ]
                ]
              ]
            }
          }
        ]
      },
      "directions":[
        {
          "routeId":1,
          "routeName":"Echo Park Ave & W Sunset Blvd, Los Angeles, California, 90026 - Flint Wash Trail",
          "summary":{
            "totalLength":11.632849349577002,
            "totalTime":18.252301588654518,
            "totalDriveTime":18.25230158430363,
            "envelope":{
              "xmin":-118.26009999999997,
              "ymin":34.076763000000028,
              "xmax":-118.20015999999998,
              "ymax":34.205680000000029,
              "spatialReference":{
                "wkid":4326,
                "latestWkid":4326
              }
            }
          },
          "features":[
            {
              "attributes":{
                "length":0,
                "time":0,
                "text":"Start at Echo Park Ave & W Sunset Blvd, Los Angeles, California, 90026",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTDepart"
              },
              "compressedGeometry":"+ha5pf-1vvvvuh+ie4mbr+0+0"
            },
            {
              "attributes":{
                "length":0.0004973141278545168,
                "time":0.0023124476668799545,
                "text":"Go northeast on Echo Park Ave toward W Sunset Blvd",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTStraight"
              },
              "compressedGeometry":"+ha5pf-1vvvvuh+ie4mbr+27+3l"
            },
            {
              "attributes":{
                "length":0.13256628266311526,
                "time":0.4291110781286302,
                "text":"Turn left on W Sunset Blvd",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTTurnLeft"
              },
              "compressedGeometry":"+ha5fj-1vvurch+ie4buv-7pm+365-3hf+1j2-d3u+5lj-4p7+243-78l+365"
            },
            {
              "attributes":{
                "length":0.097613220706877363,
                "time":0.63830571603399944,
                "text":"Turn right on Lemoyne St",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTTurnRight"
              },
              "compressedGeometry":"+ha5fj-1vvvvtg+ie4ro1+4us+8an+2qq+4ds+5r8+9id"
            },
            {
              "attributes":{
                "length":0.10052519880660588,
                "time":0.62527496509944291,
                "text":"Turn left on Montana St",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTTurnLeft"
              },
              "compressedGeometry":"+ha5cb-1vvv687+ie5ek9-e5v+8an-3bq+1ud-852+42h"
            },
            {
              "attributes":{
                "length":0.2344876577424756,
                "time":0.95997522522962198,
                "text":"Turn right on Glendale Blvd",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTTurnRight"
              },
              "compressedGeometry":"+ha5cb-1vvvvv2+ie5svu+1j3+15on+mm+ht4+5m+4ji"
            },
            {
              "attributes":{
                "length":8.9173159396382591,
                "time":9.6652116891714357,
                "text":"Continue on CA-2 N (Glendale Blvd)",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTStraight"
              },
              "compressedGeometry":"+ha5d0-1vvvvt7+ie7pvm+h1+5fu+17n+s0j+bb+7pm-17n+5lj+mn+5a7+121+8ro+29p+dku+121+66k+1oo+8ro+2ff+d3t+mm+3hg+17n+6hv+30f+851+3bq+730+sc+1dc+3hg+66k+1dd+2fe+ktj+l39+knu+kcj+5fu+54i+4jh+42h+1ue+1oo+1on+1oo+gfo+ht4+365+487+7eb+9o3+eha+k18+akf+en0+bmh+fjc+3br+4us+jah+tpb+a3f+q26+h0+243+mn+30f+364+ph5+122+psg+121+ug2+3hg+10vf+1j3+3sr+f80+mmc+6ca+66k+bs6+851+d9j+8am+4ji+2qq+4p7+30f+13eu+m5b+1goh+r9t+iv6+7pm+r47+cis+lka+bmh+1fb5+nio+10ef+ga2+fp1+8an+m5b+ebl+of4+nu2+akf+fun+973+kcj+5r8+t2l+5m+9o4-bb+6c9-a95+1q59-364+i8g-2l4+dkv-5r9+1398-h0+tpb+1j2+e0a+1dd+7pm+4jh+h0o+6hv+mb1+2qp+9o3+486+f81+1oo+6nk+4ji+esm+851+t8a+17n+4ji+121+364+244+730+4jh+gfo+2l4+91d+8am+rqt+3sr+d9k+1j3+66j+a3e+1399+lka+2c83+122+t2l-h1+4ut-486+k6t-1ue+6hv-1on+60u-3hg+a94-bgs+18ur+h1+v6o+akg+15j1+ki8+20su+3sr+c7i+ht5+1oci+ipg+1rim+ms1+273i+18jg+2fv9+730+157m-17n+hhp-5ft+lq0-1156+28gu-9co+19fs+1ud+169o+2ff+bs6+3hg+g4d+243+972+2fe+9ie"
            },
            {
              "attributes":{
                "length":0.24223833137392603,
                "time":0.24986300000000103,
                "text":"Take ramp on the right to I-210 toward Pasadena (CA-2)",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTRampRight"
              },
              "compressedGeometry":"+habfi-1vvvvuo+igel43+3br+aet+66m+ipo+7ed+vco"
            },
            {
              "attributes":{
                "length":0.21426803344249024,
                "time":0.66215700000000011,
                "text":"At fork keep right on Verdugo Blvd toward Montrose / Descanso Gardens / Hospital",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTForkRight"
              },
              "compressedGeometry":"+habk5-1vvvvss+iggmmk+7pp+kig+54k+cuc+3hh+4p9+732+con"
            },
            {
              "attributes":{
                "length":0.31928657611594069,
                "time":0.77916549571994365,
                "text":"Turn right on Verdugo Blvd",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTTurnRight"
              },
              "compressedGeometry":"+habqi-1vvvvv6+igigkk+kcq+1dd+8aq+bc+4dt+5l+54k+5m+366+0+2ff+0+488+0+54k+0+kcq+5m+91h-5m+610+0+9tt-5m"
            },
            {
              "attributes":{
                "length":0.85966976792826699,
                "time":2.0070789999999987,
                "text":"Turn right on Descanso Dr",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTTurnRight"
              },
              "compressedGeometry":"+hacl7-1vvvvka+igjf2s-bc-avv+17o-hi1+ied-977+qp7-bh0+en6-610+en7-977+8m5-avv+hnn-mml+3br-488+3hh-4p9+78p-66m+jrq-5g0+8aq-244+733-1op+610-1dd+j54-1op+9ii-2ff"
            },
            {
              "attributes":{
                "length":0.15435445846771856,
                "time":0.46874026151924869,
                "text":"Turn right on Chevy Chase Dr",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTTurnRight"
              },
              "compressedGeometry":"+hae7n-1vvvvsk+igh4e2+0-3n7+17o-4jk+dqr-est+bb-cde"
            },
            {
              "attributes":{
                "length":0.36002656856347315,
                "time":1.7651057057344284,
                "text":"Turn right on Hampstead Rd",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTTurnRight"
              },
              "compressedGeometry":"+hadst-1vvu8gk+igfl74-f2j+bb-bh1-6cc-est-mn-42i-2l5-mn-3st+91h-e66+3bs-3n7-1j3-3bs-f88-366-4l3-81k"
            },
            {
              "attributes":{
                "length":0,
                "time":0,
                "text":"Finish at Flint Wash Trail",
                "ETA":-2209161600000,
                "arriveTimeUTC":-2209161600000,
                "maneuverType":"esriDMTStop"
              },
              "compressedGeometry":"+hadst-1vvvvtf+ige7c7+0+0"
            }
          ]
        }
      ]
    }
    
  3. Go to the top of the response and find the routes and direction properties:

    • routes: contains the geometry (as a line) of the route
    • directions: an array (usually containing a single object) that represents the directions for the corresponding route
  4. Find the routes property and identify the following properties:

    • geometryType: usually esriGeometryPolyline, indicates the type of geometry of the route.
    • spatialReference: indicates the coordinate system geometries currently being returned
    • features: an array (usually with a single item) that contains the line representing the route
  5. Find the directions property, which is an array (usually containing a single item). Each set of directions has the following properties:

    • summary: summary of the entire route, contains its total duration and estimated length.
    • features: an array of objects representing each step of the directions

  1. In Postman click Code below the Send button. Select a programming language and use Postman to generate sample code for your application to run this request.

Congratulations, you're done!

You have successfully created a route and directions to the closest trailhead from a list of given trailheads.

Challenge

Add a barrier to your route

You can add barriers to restrict or impact which roads the underlying route can use. Look at the barriers, polylineBarriers, and polygonBarriers parameters in the closest facility service documentation.