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

195
Vistas
Cant get my marker's latLng to use in L.Routing.control

guys I been trying to get my markers latlon when user double click on it but still don't get any results. Been trying other methods but i think this is the most accurate since i dont get any error when executing js

Any recommendation pls

  var places = [
  ["LOCATION_1", 8.9856146341374, -79.51102268985925],
  ["LOCATION_2", 8.984640842221594, -79.51383510471848],
  ["LOCATION_3", 8.972080043026754, -79.5529245611453],
  ["LOCATION_4", 9.052896045979661, -79.4515923525883],
  ["LOCATION_5", 9.053366385577624, -79.50832832626823]
];

var map = L.map('map', {
    center: [9.352867999999996, -79.689331],//[35.791188, -78.636755],
    zoom: 9,
    layers:L.tileLayer('http://{s}.google.com/vt/lyrs=m&x={x}&y={y}&z={z}',{
        maxZoom: 20,
        subdomains:['mt0','mt1','mt2','mt3']
    })
});

for (var i = 0; i < places.length; i++) {
  marker = new L.marker([places[i][1], places[i][2]])
    .bindPopup(places[i][0])
    .addTo(map);
}

function getdest(){
   L.marker.on('dblclick',function(e){
    var latlng_dest=e.latlng()     });
  console.log(latlng_dest)
  return latlng_dest
}



navigator.geolocation.getCurrentPosition(function(location) {
  var latlng_orig = new L.LatLng(location.coords.latitude, location.coords.longitude);  
  
  
L.Routing.control({
    waypoints: [
      //L.latLng(9.10607301250145, -79.34754531445351),
      L.latLng(latlng_orig)
      //,L.latLng(latlng_dest)
      //,L.latLng(9.100769244670843, -79.35099352767948)
      ,L.latLng(getdest())
    ]
  }).addTo(map) 
  

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

0

You have many common things wrong:

  • e.latlng() is not a function it is a property e.latlng
  • L.marker.on('dblclick',function(e){ this makes no sense. You creating a new instance of a Marker without coords and then adding a listener to it.
  • You can't return a value in a function from a listener. The listener is not called at the moment you return the value L.marker.on('dblclick',function(e){ var latlng_dest=e.latlng() }); return latlng_dest

Your code should look like that:

  for (var i = 0; i < places.length; i++) {
    marker = new L.marker([places[i][1], places[i][2]])
      .bindPopup(places[i][0])
      .addTo(map)
      .on('dblclick', function(e) {
        waypoints.push(e.latlng);
        routeControl.setWaypoints(waypoints);
      });
  }

  var routeControl = L.Routing.control({
    waypoints: [],
  }).addTo(map);

  var waypoints = [];

  navigator.geolocation.getCurrentPosition(function(location) {
    var latlng_orig = new L.LatLng(location.coords.latitude, location.coords.longitude);
    waypoints.push(latlng_orig);
  });
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