Converting coordinates to route params

1648
15
Jump to solution
06-11-2018 02:40 PM
EvonFranklin
New Contributor III

How can i convert coordinates to routeparam compatible stops in order to carry out a RouteTask?

These coordinates are coming from the browser geolocation. Currently when i click on a point and then use the geolocation from the browser I get an error from attempting to solve the route, however when i click on 2 separate points the route solves successfully.

let stop = new Graphic({
geometry: new Point(position.coords.longitude,position.coords.latitude),
symbol: stopSymbol
});
routeParams.stops.features.push(stop);   
Tags (1)
0 Kudos
15 Replies
EvonFranklin
New Contributor III

I am going to try that right now, should I pass in the new geom object to the stops array in the routeparams?

0 Kudos
EvonFranklin
New Contributor III

This indeed works, so in order to use coordinates you have to convert the geometry to webmercator geometry first then push that to the routes params. Esri should make a note of this, or amend it in future releases. thanks for pointing out the suggestions I was stumped.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Evon,

   I don't think they have to be in Web Mercator it is just the fact that all the stops have to be in the same WKID.

EvonFranklin
New Contributor III

Ok I see, i guess the clicked points were not in the same wkid then.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Evon,

   Correct the clicked points would be created in the WKID of the Map. Which if you are using a standard esri basemap means that it would be WKID 102100 and the browsers geolocation will always be WKID 4326.

EvonFranklin
New Contributor III

You can see the highlighted stops in red, are completely on a roadway

0 Kudos