Select to view content in your preferred language

Run Directions widget from my own Points

934
4
11-04-2021 04:36 AM
benchikh
Regular Contributor

Hi,

I'm working with Directions widget under arcgis api js 3.38, and I want to start and run my directions from some points (lat, long) coming from my database.

so I need to pass the points to the directions widget and get the points rendered with route on the map.

Could you please help me with a sample or a code details that would be much appreciated.

Many thanks

0 Kudos
4 Replies
Noah-Sager
Esri Regular Contributor

Hi @benchikh, offhand, I don't think we have a sample that does this, but you could use the locationToAddress method on the Locator class to generate an address from each of the point. 

https://developers.arcgis.com/javascript/3/jsapi/locator-amd.html#locationtoaddress

And then pass these to the Directions widget using the addStops method.

https://developers.arcgis.com/javascript/3/jsapi/directions-amd.html#addstops

Hope this helps!

 

benchikh
Regular Contributor

Hi Many thanks for your feedback.

I did the below work, but I get just lat and lon coordinates on the source and destination inputs and did not got a label of the points " Looks like the locator did not work correctly!"

var adr = locator.addressesToLocations(new Point(-760817.9, 4031811, new SpatialReference({ wkid: 102100 })));
directionsW.addStop((adr, 100), 1);

 

could you please help ?

0 Kudos
Noah-Sager
Esri Regular Contributor

You should try the locationToAddress() method, not the addressesToLocations() method like in your code snippet above.

benchikh
Regular Contributor

Hi Many thanks, Will try it 

0 Kudos