Combining GeoLocator and selecting a destination to create route

567
1
07-20-2014 09:30 PM
JohnPapageorgiou
New Contributor III

I have a Network Analysis service that works fine in the the attached code.  I like the simplicity of adding points and a route being solved.  I'm wondering if this could be further enhanced (which may be a toll order).  What I'm trying to do is use the geoLocation sample here Geolocation | ArcGIS API for JavaScript‌, have that act as my first input point and then click on a link link inside the infoWindow of a feature in my feature layer to add it as my second input point and then have that trigger the route solve.  Would it also be possible to have turn-by-turn directions output as well?  Sort of like the sample here: Directions | ArcGIS API for JavaScript‌.  Let me know if you have any other questions or there's anything else I can provide.  Right now I can solve the route by clicking on two places on the map, but I can't get turn-by-turn directions, even getting that might be helpful.

thanks,

John

0 Kudos
1 Reply
RobertScheitlin__GISP
MVP Emeritus

John,

  This would not be to hard. The big step combining what you have with the geolocate sample. I would concentrate on this first, once you have that worked out all you need to do is use the routeParams.stops.features.push(stop); and make sure that the point you add has a spatial reference set.

var pt = new Point(location.coords.longitude, location.coords.latitude);
routeParams.stops.features.push(pt);


Now the second link from your infoWindow is a lot trickier first you would add a button to the infoWindow to fire the event that adds the second stop:


if (typeof statsLink === 'undefined') {


     var statsLink = dojo.create("a", {


          "class": "action",


          "id": 'statsLink',


          "innerHTML": "Inspect Unit",


          style: "cursor: pointer;"


     }, dojo.query(".actionList", map.infoWindow.domNode)[0]);


     on(statsLink, "click", yourFunction);


}

and yourFunction would do the same thing as the first code block i.e. add the map point to the routeParams.

Sorry I don't have time to go into more detail. This is all I have time for as I am leaving for a week long trip, hope this is enough to get you started.

0 Kudos