While going through the following Url: https://developers.arcgis.com/javascript/jssamples/widget_directions_basic.html
I found that when I view Live Sample, it is working fine.
But when I implement the Sample Code on my local machine or Download the zip file and then implement, it shows unable to route addresses.
Pic2
Also when I add the routeTaskUrl: "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route"
still it shows the same error.
Please suggest and help.
Have you setup the proxy as mentioned in that sample?
Hi, Thanks for looking into the issue.
I have used the same code mentioned in the sample. Could you please check it.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ArcGISDirections.aspx.cs" Inherits="ESRI.ArcGISDirections" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Directions Widget</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.15/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.15/esri/css/esri.css">
<style>
html, body, #map {
height:100%;
width:100%;
margin:0;
padding:0;
}
body {
background-color:#FFF;
overflow:hidden;
font-family:"Trebuchet MS";
}
</style>
<script src="https://js.arcgis.com/3.15/"></script>
<script>
require([
"esri/urlUtils", "esri/map", "esri/dijit/Directions",
"dojo/parser",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
], function(
urlUtils, Map, Directions,
parser
) {
parser.parse();
//all requests to route.arcgis.com will proxy to the proxyUrl defined in this object.
urlUtils.addProxyRule({
urlPrefix: "route.arcgis.com",
proxyUrl: "/sproxy/"
});
urlUtils.addProxyRule({
urlPrefix: "traffic.arcgis.com",
proxyUrl: "/sproxy/"
});
var map = new Map("map", {
basemap: "streets",
center:[-98.56,39.82],
zoom: 4
});
//travelModesServiceUrl option points to logistics service hosted from ArcGIS Online
//by indicating this URL, a login prompt should not display
var directions = new Directions({
map: map,
routeTaskUrl: "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Network/USA/NAServer/Route",
travelModesServiceUrl: "http://utility.arcgis.com/usrsvcs/servers/cdc3efd03ddd4721b99adce219629489/rest/services/World/Utili..."
},"dir");
directions.startup();
});
</script>
</head>
<body class="claro">
<div data-dojo-type="dijit/layout/BorderContainer"
data-dojo-props="design:'headline', gutters:false"
style="width:100%;height:100%;">
<div data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'right'"
style="width:250px;">
<div id="dir"></div>
</div>
<div id="map"
data-dojo-type="dijit/layout/ContentPane"
data-dojo-props="region:'center'">
</div>
</div>
</body>
</html>
Hello Alok,
The code is not the problem, you need a proxy service/application setup in order to process request. Check this out, it will give information about proxy and how to set it up.
Using the proxy | Guide | ArcGIS API for JavaScript
Hope this was helpful.
Thejus