Select to view content in your preferred language

Routes won't render to the screen

938
2
02-19-2021 01:11 AM
OctavianSirbu
New Contributor

Hello,

I built a React Native component in Kotlin. I used a SimpleViewManager type of class to expose this component to React Native and I use it to render an esri map. The problem is I cannot use RouteTask properly for creating a route between 2 points on the map and I do not know where the problem is.

This is the function that I use:

 

 

private fun findRoute() {
        val routeTask = RouteTask(
                context,
                "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"
        )

        val routeParametersFuture = routeTask.createDefaultParametersAsync()
        routeParametersFuture.addDoneListener {
            try {
                val routeParameters = routeParametersFuture.get().apply {
                    isReturnDirections = true
                    setStops(routeStops)
                }

                // get the route and display it
                val routeResultFuture = routeTask.solveRouteAsync(routeParameters)
                routeResultFuture.addDoneListener {
                        val result = routeResultFuture.get()
                        val routes = result.routes
                        if (routes.isNotEmpty()) {
                            val route = routes[0]

                            val shape = route.routeGeometry
                            val routeGraphic = Graphic(
                                    shape,
                                    SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.BLUE, 2f)
                            )
                            graphicsOverlay.graphics.add(routeGraphic)
                        }
                }
            } catch (e: Exception) {
                val error = "Error creating default route parameters: " + e.message
                Toast.makeText(context, error, Toast.LENGTH_LONG).show()
                Log.e(ArcGISViewMaps::class.simpleName, error)
            }
        }
    }

 

 

and I use it in createViewInstance of the SimpleViewManager class that I mentioned before. See below:

 

 

override fun createViewInstance(reactContext: ThemedReactContext): MapView {
        val view = MapView(reactContext)
        ArcGISRuntimeEnvironment.setApiKey("myAPI")
        val map = ArcGISMap(BasemapStyle.ARCGIS_STREETS)
        view.map = map
        view.setViewpoint(Viewpoint(latitudeDefault, longitudeDefault, 72000.0))
        view.graphicsOverlays.add(graphicsOverlay)
        val pointDisplay1 = Point(longitudeDefault, latitudeDefault, SpatialReferences.getWgs84())
        addStop(Stop(pointDisplay1))
        val pointDisplay2 = Point(-6.2603,53.37,SpatialReferences.getWgs84())
        addStop(Stop(pointDisplay2))
        findRoute()
        return view
    }

 

 

 

As a context for the RouteTask I use reactContext. I am passing that context from the package manager where I call this class to be exposed to React Native.

 

Finally, it shows an error that I catch and expose in React Native, the error says: 

"Error creating default route parameters: com.esri.arcgisruntime.ArcGISRuntimeException: Invalid call.: Object failed to load, unable to execute task."

If you have any ideas regarding this issue, please do let me know as soon as possible.

Thank you!

0 Kudos
2 Replies
RamaChintapalli
Esri Contributor

Hi,

Does the `reactContext` provides the application or activity context?

Also were you able to perform route task operations outside of React Native setup, like running this tutorial.

https://developers.arcgis.com/android/route-and-directions/tutorials/find-a-route-and-directions/

Thanks

Rama

0 Kudos
Jotded
by
New Contributor

Not sure if you'll receive this as this is an old post, but I'm having the exact same issue rn. If you have found a solution to this can you please share with me, thanks! 

 

0 Kudos