I have an application that uses my Leaflet map. I want to use it like navigation. But the path is not updated. Where is the problem?

setInterval(livetrack, 5000);
function livetrack() {
  $.get("/xxxx?car_id=" + carid).done(function (data) {
    var xvar = data;
    if (new_marker != "") map.removeLayer(new_marker);

    var b = xvar.split(",");

    new_marker = L.marker([b[1], b[2]], { icon: iconCar }).addTo(map);

    lati = b[1];
    longi = b[2];


function another_func() {
  /* etc */
  /* etc */

function rotate_update(data) {
  veriler = L.Routing.control({
    show: false,
    addWaypoints: false,
    draggableWaypoints: false,
    fitSelectedRoutes: false,
    autoRoute: true,
    waypoints: [
      L.latLng(lati, longi),
      L.latLng(data.last_lati, data.last_longi, iconCus),
    createMarker: function (i, wp, nWps) {
      if (i === 0 || i === nWps + 1) {
        return (mymarker = L.marker(wp.latLng, {
          icon: iconCar,
      } else {
        return (job_start = L.marker(wp.latLng, {
          icon: iconCus,

In this way, the code creates 2 car icons and 1 customer icon. The 1st car icon continues on its way live, but does not draw a route to it. The second car creates the route between the icon and the customer, but this car icon is not moving.

How can I delete one of these icons and update the route live?

  • Native Leaflet does not include L.Routing control. Please edit your question and add info about that: what this is and what it should do in your app. – TomazicM Mar 31 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.