Error in Solving Route

180
3
Jump to solution
01-17-2020 07:18 AM
Highlighted
New Contributor

Michael Branscomb

Hello,

I'm writing a mobile Xamarin Android app that uses a network analysis service (NAS) to find routes.
This is my work environment:

Windows 7 Pro

Visual Studio 2019 Professional

ArcGIS Runtime SDK 100.7

ArcGIS Server 10.7.1

The NAS uri is Route (NAServer) 

This Routing Service has no GTFS, just the street routing information.

To create a route task and solve it, I use this code:

RouteTask solveRouteTask = await RouteTask.CreateAsync(_routeServiceUri);

// Get the default parameters from the route task (defined with the service)
RouteParameters routeParams = await solveRouteTask.CreateDefaultParametersAsync();

// Make some changes to the default parameters
routeParams.ReturnStops = true;
routeParams.ReturnDirections = true;

// Set the list of route stops that were defined at startup
routeParams.SetStops(_routeStops);

// Solve for the best route between the stops and store the result
RouteResult solveRouteResult = await solveRouteTask.SolveRouteAsync(routeParams);

// Get the first (should be only) route from the result
Route firstRoute = solveRouteResult.Routes.First();

// Get the route geometry (polyline)
Polyline routePolyline = firstRoute.RouteGeometry;

// Create a thick purple line symbol for the route
SimpleLineSymbol routeSymbol = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Purple, 8.0);

// Create a new graphic for the route geometry and add it to the graphics overlay
Graphic routeGraphic = new Graphic(routePolyline, routeSymbol);
_routeGraphicsOverlay.Graphics.Add(routeGraphic);

// Get a list of directions for the route and display it in the list box
DirectionsListBox.ItemsSource = firstRoute.DirectionManeuvers.Select(direction => direction.DirectionText);

Route Stop Parameters:

MapPoint fromPoint = (MapPoint)GeometryEngine.Project(currentLoc, new SpatialReference(2247));
MapPoint toPoint = (MapPoint)GeometryEngine.Project(tappedpoint, new SpatialReference(2247));

From and To Points are in Stateplane.

I am getting the below exception at :

await solveRouteTask.SolveRouteAsync(routeParams);

Exception:

{Esri.ArcGISRuntime.Http.ArcGISWebException: Unable to complete operation.
at Esri.ArcGISRuntime.Http.ArcGISHttpClientHandler+ArcGISClientHandlerInternal.SendAsync (System.Net.Http.HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) [0x00a1a] in <fe6820dba09a468695234a822154bd83>:0
at System.Net.Http.HttpClient.FinishSendAsyncUnbuffered (System.Threading.Tasks.Task`1[TResult] sendTask, System.Net.Http.HttpRequestMessage request, System.Threading.CancellationTokenSource cts, System.Boolean disposeCts) [0x000b3] in /Users/builder/jenkins/workspace/archive-mono/2019-08/android/release/external/corefx/src/System.Net.Http/src/System/Net/Http/HttpClient.cs:531
at Esri.ArcGISRuntime.ArcGISException.HandleCoreError (RuntimeCoreNet.GeneratedWrappers.CoreError error, System.Boolean throwException) [0x00013] in <fe6820dba09a468695234a822154bd83>:0
at RuntimeCoreNet.GeneratedWrappers.Interop.CheckError (System.IntPtr errorHandle, System.Boolean throwOnFailure, System.Runtime.InteropServices.GCHandle wrapperHandle) [0x0002e] in <fe6820dba09a468695234a822154bd83>:0
at RuntimeCoreNet.GeneratedWrappers.CoreTask.Get () [0x00019] in <fe6820dba09a468695234a822154bd83>:0
at Esri.ArcGISRuntime.Internal.CoreTaskExtensions+TaskCompletedCallbackHandler`1.OnCompleted (System.Object sender, System.EventArgs e) [0x00034] in <fe6820dba09a468695234a822154bd83>:0
--- End of stack trace from previous location where exception was thrown ---

at Esri.ArcGISRuntime.Internal.CoreTaskExtensions+TaskCompletedCallbackHandler`1.CreateInternal (RuntimeCoreNet.GeneratedWrappers.CoreTask task, System.Threading.CancellationToken cancellationToken) [0x0007f] in <fe6820dba09a468695234a822154bd83>:0

Network Analyst

1 Solution

Accepted Solutions
Highlighted
New Contributor II

Michael Branscomb‌ 

Fixed the issue.

Issue was that when using Xamarin Forms and real android and iOS devices instead of simulators, will return Z value when getting current location and one of my stops does not have a Z value.

To fix this I had to parse XY to a mappoint and then project it to state plane, so that they can be used as stops.

MapPoint tappedpoint = e.Location; MapPoint currentLoc = new MapPoint(MyMapView.LocationDisplay.Location.Position.X, MyMapView.LocationDisplay.Location.Position.Y, new SpatialReference(4326));
MapPoint fromPoint = (MapPoint)GeometryEngine.Project(currentLoc, new SpatialReference(2247));
MapPoint toPoint = (MapPoint)GeometryEngine.Project(tappedpoint, new SpatialReference(2247));‍‍‍‍‍‍‍‍‍

View solution in original post

3 Replies
Highlighted
Esri Frequent Contributor

Hi,

The error message `Unable to complete operation.` is the error received from from the service. It usually indicates that there is a problem with the parameters.

You could try going to the REST endpoint for your server (e.g. NetworkAnalysis/SanDiego (NAServer)) and entering the same values to determine if it still fails. Then iterate on the values you're entering to determine what the issue might be. For example, what is the spatial reference of the stops and versus the spatial reference of the network?

Since you mention Windows 7, note that our current 100.7 release is the last release that is certified for Windows 7. At the next release (100.8) the minimum requirement will be Windows 10 version 1803 (April 2018).

Cheers

Mike

Reply
0 Kudos
Highlighted
New Contributor

Michael,

I used the same parameters on the rest endpoint and it's giving me the result, below is the URL to the result with parameters. My NAS, Output SR and the supplied stop features are in the same Spatial reference (state plane wkid 2247). But when using in Xamarin Forms ArcGIS Runtime, it is throwing exception.

https://comgistest.memphistn.gov/arcgis/rest/services/Routing/StreetsRouting/NAServer/Route/solve?st...

Reply
0 Kudos
Highlighted
New Contributor II

Michael Branscomb‌ 

Fixed the issue.

Issue was that when using Xamarin Forms and real android and iOS devices instead of simulators, will return Z value when getting current location and one of my stops does not have a Z value.

To fix this I had to parse XY to a mappoint and then project it to state plane, so that they can be used as stops.

MapPoint tappedpoint = e.Location; MapPoint currentLoc = new MapPoint(MyMapView.LocationDisplay.Location.Position.X, MyMapView.LocationDisplay.Location.Position.Y, new SpatialReference(4326));
MapPoint fromPoint = (MapPoint)GeometryEngine.Project(currentLoc, new SpatialReference(2247));
MapPoint toPoint = (MapPoint)GeometryEngine.Project(tappedpoint, new SpatialReference(2247));‍‍‍‍‍‍‍‍‍

View solution in original post