Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am a beginner in ArcGIS and I was following this tutorial. I am trying to find a route between two points. I created a sample application, in which first, i get the two points on map single tap as follows

@Override
        public boolean onSingleTap(final MotionEvent e)
        {
            Point point = map.toMapPoint(new Point(e.getX(), e.getY()));
            points.add(point);
            if (points.size() == 2)
            {
                new FindRouteTask().execute();
            }
            return true;
        }

and my FindRouteTask is as follows

private class FindRouteTask extends AsyncTask<Void, Void, RoutingResult>
    {

        ProgressDialog  dialog  = new ProgressDialog(FindeRouteActivity.this);
        RoutingResult   mResults;

        @Override
        protected void onPreExecute()
        {
            dialog.setMessage("Finding routes...");
            dialog.show();
        }

        @Override
        protected RoutingResult doInBackground(Void... params)
        {
            RoutingParameters routeParams = new RoutingParameters();
            routeParams.setImpedanceAttributeName("Length");

            String routeTaskURL = "http://tasks.arcgisonline.com/ArcGIS/rest/services/NetworkAnalysis/ESRI_Route_NA/NAServer/Route";
            RoutingTask routeTask = new RoutingTask(routeTaskURL, null);

            NAFeaturesAsFeature naFeatures = new NAFeaturesAsFeature();
            // Create the stop points from point geometry
            StopGraphic startPnt = new StopGraphic(points.get(0));
            StopGraphic endPnt = new StopGraphic(points.get(1));
            // set features on routing feature class
            naFeatures.setFeatures(new Graphic[] { startPnt, endPnt });
            // set stops on routing feature class
            routeParams.setStops(naFeatures);
            try
            {
                mResults = routeTask.solve(routeParams);
            } catch (Exception e)
            {
                e.printStackTrace();
                return null;
            }
            return mResults;
        }

        @Override
        protected void onPostExecute(RoutingResult result)
        {
            dialog.dismiss();
            points.clear();
            if (result == null || !result.getRoutes().isEmpty())
            {
                Toast.makeText(FindeRouteActivity.this, "There was some problem in fetching the routes. Please try again!", Toast.LENGTH_SHORT).show();
            } else
            {
                findRoute(result.getRoutes().get(0));
            }
        }

    }

But the problem is that routeTask.solve(routeParams) always throws a exception

Failed to convert the input propertyset into a recordset to load into the NAClass "Stops".  The coordinates or measures are out of bounds.  

Could anyone please tell me what am I doing wrong and what the problem is??
-Thanks in advance

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The problem was that we need to set the spatial reference of the naFeatures that we were sending. Hence

naFeatures.setSpatialReference(mMapView.getSpatialReference());

solved the problem!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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