Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda