Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!