3

i've been trying very hard to create a route between two points(startPoint, endPoint). But i am getting the following error:

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.

Here is my code:

private final String routeTaskURL = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mMapView = (MapView) findViewById(R.id.map);
    mMapView.enableWrapAround(true);
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                UserCredentials userCredentials = new UserCredentials();
                userCredentials.setUserToken(token, clientID);
                RouteTask routeTask = RouteTask.createOnlineRouteTask(routeTaskURL, userCredentials);
                RouteParameters routeParameters = routeTask.retrieveDefaultRouteTaskParameters();
                NAFeaturesAsFeature naFeatures = new NAFeaturesAsFeature();
                SimpleMarkerSymbol sms = new SimpleMarkerSymbol(
                        Color.RED, 5, SimpleMarkerSymbol.STYLE.CIRCLE);

                Point startPoint = new Point(36.793653, -119.866896);
                Point stopPoint = new Point(36.795488, -119.853345);

                Graphic graphic1 = new Graphic(startPoint, sms);
                Graphic graphic2 = new Graphic(stopPoint, sms);

                StopGraphic startPnt = new StopGraphic(graphic1);
                StopGraphic stopPnt = new StopGraphic(graphic2);

                naFeatures.setFeatures(new Graphic[] {startPnt, stopPnt});
                routeParameters.setStops(naFeatures);

                RouteResult mResults = routeTask.solve(routeParameters);
                System.out.println(mResults.getStops());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }).start();
}

I've searched the internet. Many developers were/are facing this problem. I've tried all the solutions but none of them worked. I got routeTaskURL from the ArcGIS Routing Sample app. The link which is given in the documentation of ArcGIS maps gives me the 403 error if i open it in the browser.

Note: "token" and "clientID" is declared in the first step and they both are taken from the ArcGIS developers console where i registered my application.

  • Have you tested the route network in ArcMap? I think the network isn't connected properly. – Stefan Jan 29 '16 at 15:29
  • @Stefan I'm sorry i don't know what route network is and how to use it. I believe it is for ArcGIS Desktop. Can you please elaborate? Any link for the guide? – Linux Holic Jan 29 '16 at 16:07
0

It will work if you switch your X and Y values. See https://stackoverflow.com/a/35139941/720773 for a full description of what is happening.

  • Thanks you solved my problem. But can you look at my updated code and see why route is not displaying on map. I've added all the necessary graphic layers. Code Link: paste.ubuntu.com/14856322 – Linux Holic Feb 2 '16 at 10:17
0

I don't think you are allowed to use http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route

In a production app.

Esri has paid options for directions services to use instead.

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.