Converting coordinates to route params

1597
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
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Yes you can but it believe it will expect that all stops be in the same WKID. So just use webmercatorutils geographictowebmercator

https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.webmercatorutils-amd.html#geographict... 

View solution in original post

0 Kudos
15 Replies
RobertScheitlin__GISP
MVP Emeritus

Evon,

   I would add a spatial reference.

let stop = new Graphic({
  geometry: new Point(position.coords.longitude,position.coords.latitude, new SpatialReference({ wkid: 4326 })),
  symbol: stopSymbol
});
routeParams.stops.features.push(stop);‍‍‍‍‍
0 Kudos
EvonFranklin
New Contributor III

Let me go try that now, but if it is something so simple I am going to beat myself lol. I don't know why i wouldn't think of that.

0 Kudos
EvonFranklin
New Contributor III

Actually adding a spatial reference to the point object, results in the point not being symbolized on the map at all

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Try this then:

let pnt = new Point(position.coords.longitude,position.coords.latitude, new SpatialReference({ wkid: 4326 }));
let stop = new Graphic(pnt, stopSymbol);
routeParams.stops.features.push(stop);‍‍‍‍
0 Kudos
EvonFranklin
New Contributor III

Still not working, if i click and add two points it will work but it seems the calculated geo position from the browser longitude and latitude just doesn't convert at all.

let stop = new Graphic({
geometry: new Point(position.coords.longitude,position.coords.latitude),
symbol: stopSymbol
});
This part here
0 Kudos
EvonFranklin
New Contributor III

The point shows up on the map, it just won't carry out the routing

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Evon,

   This is pretty strange. I wonder if it is the fact that the geoloaction graphic is WGS84 and the other graphics in the stops array are WebMercator 102100.

0 Kudos
EvonFranklin
New Contributor III

That could be the case, because the routing works when i manually click two points. At the same time though Robert, the symbol for the marker (the black cross) shows up at the right point on the map. This is crazy, can I just add the point to the stops.features?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Yes you can but it believe it will expect that all stops be in the same WKID. So just use webmercatorutils geographictowebmercator

https://developers.arcgis.com/javascript/3/jsapi/esri.geometry.webmercatorutils-amd.html#geographict... 

0 Kudos