Select to view content in your preferred language

RouteTask Failed to Load Cause Msg: Token Required

176
5
3 weeks ago
MottainaiRecycling
Emerging Contributor

Hello,

I'm using ArcGIS Maps Sdk version:

implementation 'com.esri.arcgisruntime:arcgis-android:100.15.6'

I' getting this below error while want to draw route path using multiple stop points in ArcGIS mapview

RouteTask Failed to Load Cause: com.esri.arcgisruntime.io.JsonEmbeddedException: Token Required
RouteTask Failed to Load Cause Msg: Token Required

Please find the below code to draw route between multiple points:

private fun drawRouteBetweenMultiplePointArcGIS(listOfStops: ArrayList<Stop>) {
Log.e(TAG, "######Inside drawRouteBetweenMultiplePointArcGIS########")
Log.e(TAG, "listOfStops Size: ${listOfStops.size}")

// Load RouteTask before using it
routeTask.loadAsync()
routeTask.addDoneLoadingListener {
Log.e(TAG, "@@@Inside routeTask.addDoneLoadingListener")
Log.e(TAG, "routeTask.loadStatus ${routeTask.loadStatus}")
Log.e(TAG, "RouteTask Failed to Load: ${routeTask.loadError.message}")
Log.e(TAG, "RouteTask Failed to Load Cause: ${routeTask.loadError.cause}")
Log.e(TAG, "RouteTask Failed to Load Cause Msg: ${routeTask.loadError.cause?.message}")
if (routeTask.loadStatus == LoadStatus.LOADED) {
Log.e(TAG, "@@@Inside LoadStatus.LOADED")
// Create Route Parameters
val routeParamsFuture = routeTask.createDefaultParametersAsync()
routeParamsFuture.addDoneListener {
val routeParams = routeParamsFuture.get()
routeParams.isReturnRoutes = true
routeParams.isReturnDirections = true
routeParams.isFindBestSequence = true // Enables shortest path optimization

// Get available travel modes and set driving mode
val travelModes = routeTask.routeTaskInfo.travelModes
val drivingMode = travelModes.find { it.name.contains("Driving", true) }
if (drivingMode != null) {
routeParams.travelMode = drivingMode
}


routeParams.setStops(listOfStops)

// Solve Route
val routeResultFuture = routeTask.solveRouteAsync(routeParams)
routeResultFuture.addDoneListener {
val routeResult = routeResultFuture.get()
if (routeResult.routes.isNotEmpty()) {
val route = routeResult.routes[0] // Get the best route
drawPolylineArcGIS(route) // Draw route on map
}
}
}
}
}
}

 

private fun drawPolylineArcGIS(route: Route) {
val routeGeometry = route.routeGeometry

// Create line symbol
val lineSymbol = SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLUE, 10f)

// Create polyline graphic
polylineGraphic = Graphic(routeGeometry, lineSymbol)

// Add route graphic to map
mGraphicsOverlay.graphics.add(polylineGraphic)
}
 
I'm using runtime API key to validate ArcGIS mapView:
 
private fun setArcMapAPIKey() {
ArcGISRuntimeEnvironment.setApiKey(Constant.ARCGIS_MAP_API_KEY)
}
 
Show currently, what steps need to be taken to solve this above issue?
kindly suggest.
Tags (1)
0 Kudos
5 Replies
RamaChintapalli
Esri Contributor

Hi,

What is the url of your route service? If you are using an API Key, does your API Key has privileges to access your route service?

Thanks
Rama

0 Kudos
MottainaiRecycling
Emerging Contributor

Url For Route Service:

 
API key access type:
Creator
0 Kudos
RamaChintapalli
Esri Contributor

Can you go to the Developer Credential (API key) portal item and in the settings tab, do you see Routing enabled in available services ?

DeveloperCredential-Routing.png




0 Kudos
MottainaiRecycling
Emerging Contributor

Yes Routing service is enabled on the used api key.

0 Kudos
RamaChintapalli
Esri Contributor

If the API key has the permissions to access route service, I expect it to work. You if you have network debug tools (like Charles) to trace the traffic, you can see the logs to understand which token being used for the route solve operation and whether token being applied or not correctly.

Also, would it be possible for you to share a repro case (similar to this sample) privately with me or contact customer support to debug into your app?

0 Kudos