1

I was trying to run a sample project "Routing" provided by ArcGis Runtime SDK. I tried the code but when the method solve() of RouteTask class is executed, it throws the following exception without returning any routes:

com.esri.core.io.EsriServiceException: Unable to complete operation. Location "Location 1" in "Stops" is unlocated. Location "Location 2" in "Stops" is unlocated. Need at least 2 valid stops. "Stops" does not contain valid input for any route.

I am not able to figure out what the actual problem is. Here is the link for the sample code and the code looks like this:

        map.setOnLongPressListener(new OnLongPressListener() {

        private static final long serialVersionUID = 1L;

        public boolean onLongPress(final float x, final float y) {

            // Clear the graphics and empty the directions list
            routeLayer.removeAll();
            hiddenSegmentsLayer.removeAll();
            curDirections = new ArrayList<String>();
            mResults = null;

            // retrieve the user clicked location
            final Point loc = map.toMapPoint(x, y);

            // Show that the route is calculating
            dialog = ProgressDialog.show(RoutingSample.this, "",
                    "Calculating route...", true);
            // Spawn the request off in a new thread to keep UI responsive
            Thread t = new Thread() {

                @Override
                public void run() {
                    try {
                        // Start building up routing parameters
                        RouteParameters rp = mRouteTask
                                .retrieveDefaultRouteTaskParameters();
                        NAFeaturesAsFeature rfaf = new NAFeaturesAsFeature();
                        // Convert point to EGS (decimal degrees)
                        Point p = (Point) GeometryEngine.project(loc, wm,
                                egs);
                        // Create the stop points (start at our location, go
                        // to pressed location)
                        StopGraphic point1 = new StopGraphic(mLocation);
                        StopGraphic point2 = new StopGraphic(p);
                        rfaf.setFeatures(new Graphic[] { point1, point2 });
                        rfaf.setCompressedRequest(true);
                        rp.setStops(rfaf);
                        // Set the routing service output SR to our map
                        // service's SR
                        rp.setOutSpatialReference(wm);

                        // Solve the route and use the results to update UI
                        // when received
                        mResults = mRouteTask.solve(rp);
                        mHandler.post(mUpdateResults);
                    } catch (Exception e) {
                        Log.w(ESRI_EXCEPTION_TAG, e);
                        mException = e;
                        mHandler.post(mUpdateResults);
                    }
                }
            };
            // Start the operation
            t.start();
            return true;
        }

I get exception on the following line: mResults = mRouteTask.solve(rp);

  • You do not need to generate a token to work with this sample. The error you are getting is related to a location not being properly geocoded. Please detail the steps you do to reproduce the error. – jdONeill Aug 19 '14 at 18:51
  • @jdONeill I was accessing the wrong Rest service so the location was not detectable. So, if you want to reproduce the error, you can change the url which does not cover your location or the area that you are targetting in your app. – Puneetr90 Aug 20 '14 at 6:28
1

I got this one myself. The problem was the rest API url that I was calling.Please follow the steps below:

  1. I had to generate the access token as mentioned in this link.

  2. After that, change your url to this http://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_India (As I was looking for routes in India)

  3. Than in your code, along with the above url, you will also have to pass a UserCredential object like like this:

    UserCredentials authenticate= new UserCredentials();
        authenticate.setUserToken(TOKEN,CLIENT_ID);
        mRouteTask = RouteTask
                .createOnlineRouteTask(
                        "http://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_India",
                        authenticate);
    

TOKEN and CLIENT_ID is generated in step 1.

Hope it helps someone.

  • Glad you solved your issue, to be clear though, you don't need a TOKEN or CLIENT_ID to work directly with the sample – jdONeill Aug 22 '14 at 19:33
  • @jdONeill in my case , I needed one as when I tried without token it showed me unauthorized access.Also u must have using some other url. thats y u dint need any token. :) – Puneetr90 Aug 23 '14 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.