Calculate markers in a 2 points Routing.control route on leaflet


I am using Leaflet and routing.control to show a route, the route is A to B on road, but I need to calculate some points in the middle of the route generated.

The code I am using to generate the route is the following:

this.arrRoutesLatLng[0] = this.createLatLng(this.loc_origen.latitud, this.loc_origen.longitud);
this.arrRoutesLatLng[1] = this.createLatLng(this.loc_destino.latitud, this.loc_destino.longitud);

// Crear la ruta entre los puntos A y B, se permite añadir puntos intermedios.
this.routeControl = L.Routing.control({
  showAlternatives: false,
  lineOptions: {styles: [{color: '#242c81', weight: 7}]},
  fitSelectedRoutes: false,
  altLineOptions: {styles: [{color: '#ed6852', weight: 7}]},
  // routeWhileDragging: true,
  waypoints: arrayCoordsLatLng,
  plan: new L.Routing.Plan(arrayCoordsLatLng, {
    addWaypoints: true,
    draggableWaypoints: true,

and I get this situation:

enter image description here

But I need score this one:

enter image description here

I’ve tried with the routing API without results so I was wanting a library able to calculate the coordinates of the road thaks to the bounds of the map and the svg generated by the road.

Any library that could do this?
Another possible solution?

Reading you, Thanks!!

Source: Angular Questions

Categorized as angular, leaflet, maps, openstreetmap Tagged , , ,


Solution was to not convert to JSON

alert (routeArray[0].latLng.lng);

Miss Mia Volkman

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us