search and route solving fuctions

2005
6
07-05-2016 06:36 AM
MuhamedRedzic
New Contributor

Hello, i'm using the search and the route solving functions. The thing is, sometimes i can find a point on the map with the search function, but the same text can't be reused to mark the start/end point for the route solving function. Is there a solution for this ?

Thanks for you help

Tags (3)
0 Kudos
6 Replies
PanagiotisPapadopoulos
Esri Regular Contributor

try to take the location from search tool and pass this as direction stop on direction widget

location is the geometry from search result

location = webMercatorUtils.webMercatorToGeographic(location);

var CoordsforStop = "" + location.x + "," + location.y +"";

directions.updateStop(CoordsforStop,1);

0 Kudos
MuhamedRedzic
New Contributor

Thanks for your answer, but i don't really understand.

how can i get the location out of this :

var searchFrom = new Search({

   map: map
}, "fromTxf");

thanks again for your help

0 Kudos
PanagiotisPapadopoulos
Esri Regular Contributor

You can use the select - results event in order to identify the selected item from the list

Search | API Reference | ArcGIS API for JavaScript 3.17

from the result take the item geometry and push it on location parameter.

0 Kudos
PanagiotisPapadopoulos
Esri Regular Contributor

something like that

require([
...
], function( ... )
   on
(s,'select-result', function(e) {
      var location = e.geometry;

     location = webMercatorUtils.webMercatorToGeographic(location);

     var CoordsforStop = "" + location.x + "," + location.y +"";

     directions.updateStop(CoordsforStop,1);


     
});
  
...
});

0 Kudos
MuhamedRedzic
New Contributor

Thanks for your help it worked in the end !

0 Kudos
PanagiotisPapadopoulos
Esri Regular Contributor

glad to help you. if you want mark the question as correct answer.

0 Kudos