2

I have a project where in I have a source and a destination, but in between there can be any number of stop points. I need to display a route from source to destination covering all the stop points.

I started finding route between two points and is working fine. But the moment I add a extra point in between it gives a error saying

Location "Location 3" in "Stops" is unlocated. Location "Location 2" in "Stops" is on a soft-restricted network element. Cannot preserve last location "Location 3" in "Stops" because it is invalid. "Stops" does not contain valid input for any route.

I tried googling for this error but couldn't find any results.

I thought location 3 is not a valid location but when I try to find a route between source and location 3 it works fine. I am not sure what I am doing wrong. Below I have attached function which gives route result.

private void QueryDirections(final ArrayList<Point> stopPoints) {

dialog = ProgressDialog.show(RoutingSample.this, "Routing Sample",
        "Calculating route...", true);
Thread t = new Thread() {
    @Override
    public void run() {
        try {
            // Start building up routing parameters
            NAFeaturesAsFeature stops = new NAFeaturesAsFeature();
            ArrayList<StopGraphic> stopGraphics = new ArrayList<StopGraphic>();
            for(Point pt : stopPoints){
                stopGraphics.add(new StopGraphic(pt));
            }
            Graphic[] stopGraphicsPrim = new Graphic[stopGraphics.size()];
            stopGraphicsPrim = stopGraphics.toArray(stopGraphicsPrim);
            stops.setSpatialReference(wm);
            stops.setFeatures(stopGraphicsPrim);
            stops.setCompressedRequest(true);
            RouteParameters rp = mRouteTask
                    .retrieveDefaultRouteTaskParameters();
            rp.setStops(stops);
            rp.setReturnDirections(true);
            rp.setFindBestSequence(true);
            rp.setPreserveFirstStop(true);
            rp.setOutSpatialReference(wm);

            // I get error here. When routeTast.solve is called. Please help

            mResults = mRouteTask.solve(rp);
            mHandler.post(mUpdateResults);
        } catch (Exception e) {
            mException = e;
            e.printStackTrace();
            dialog.dismiss();
            mHandler.post(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(getApplicationContext(),"directions cannot be found ",Toast.LENGTH_SHORT).show();
                }
            });
        }
    }
};
// Start the operation
t.start();

}

I was referring to a similar post Finding shortest route between multiple stops using ArcGIS for Android? but I wasn't able to get any solution from this.

Your Answer

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

Browse other questions tagged or ask your own question.