AnsweredAssumed Answered

Generate Routes from User Location - Direction Widget

Question asked by siva.lntgis on Jul 24, 2018

Hi 

When i click the Get Directions button or did an internal call to get the directions, it is not taking my current position for the route calculation. And i have included the piece of code directions.useMyCurrentLocation(stopIndex) to include my current location.

 

how to overcome this issue.

 

Please refer the screenshot and the code for the same.

 

 

 

<!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.25/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.25/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.25/"></script>
<script>
require([
"esri/urlUtils", "esri/map", "esri/dijit/Directions","esri/dijit/LocateButton",
"dojo/parser",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
], function(
urlUtils, Map, Directions,LocateButton,
parser
) {
parser.parse();
var map = new Map("map", {
basemap: "streets",
center:[-98.56,39.82],
zoom: 4
});
var geoLocate = new LocateButton({
map: map,
highlightLocation: true
}, "LocateButton"
);
geoLocate.startup();
//default will point to ArcGIS world routing service
var directions = new Directions({
map: map
// --------------------------------------------------------------------
// New constuctor option and property showSaveButton added at version
// 3.17 to allow saving route. For more information see the API Reference.
// https://developers.arcgis.com/javascript/3/jsapi/directions-amd.html#showsavebutton
//
// Uncomment the line below to add the save button to the Directions widget
// --------------------------------------------------------------------
// , showSaveButton: true
},"dir");
directions.startup();

on(dom.byId("LocateButton"), "click", function () {

directions.useMyCurrentLocation(0);
directions.getDirections();
});

});
</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 id="LocateButton"></div>
</div>
</div>
</body>
</html>

 

Thanks & Regards

Siva

Outcomes