Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

157
Vistas
leaflet routing machine - IRoute.summary.totalDistance

I am using Leaflet 1.2.0 and Leaflet Routing Machine 3.2.12.

My code is drawing the correct route on the map, yet, when i want to access the summary and the totalDistance from the summary, both are undefined. Why is that?

function createRoute(id, coords) {
            route = L.Routing.control({
                    name: id,
                    serviceUrl: 'http://router.project-osrm.org/route/v1',
                    //router: L.Routing.graphHopper('apiKey');
                    waypoints: coords, //way_points,
                    addWaypoints: false,
                    draggableWaypoints: false,
                    show: false,
                }).on('routesfound', function(e) {
                    console.log(this.summary.totalDistance);
                    // console.log(route.summary.totalDistance);
                     
                })
                    //.on('routesfound', function(e) {
                    //    routes = e.routes;  //is declared and instantiated before the function 
                    //                        // createRoute
                    //    RouteLength = routes[0].summary.totalDistance;
                    //});
                .addTo(map);
    }

The error: Routing Error: status -3 TypeError: Cannot read properties of undefined (reading 'totalDistance').

From the console i get the escalation of:

fire    @   leaflet.js:5
(anonym)    @   leaflet-routing-machine.js:16166
(anonym)    @   leaflet-routing-machine.js:18004
loaded  @   leaflet-routing-machine.js:46
load (asynchron)        
corslite    @   leaflet-routing-machine.js:53
route   @   leaflet-routing-machine.js:17977
route   @   leaflet-routing-machine.js:16151
onAdd   @   leaflet-routing-machine.js:15919
addTo   @   leaflet.js:5
createRoute @   POI-Dash implement Routing.html:586

Anyone know more about it?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

this doesn't have a summary. You will need to refer to e.routes, like e.routes[0].summary.totalDistance.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda