2

I'm doing an Uber-like app. There is no problem in live tracking, but when I need to direct the vehicle somewhere, there are 3 markers on the map. 1st marker live tracking. The 2nd is the starting point and the 3rd marker is the target. Normally, there should be 2 grocery stores. My instant location and destination. I have a problem somewhere but I could not solve the problem. How can I fix this problem?

Live tracking that works without this request:

<script type="text/javascript">
var timer_control = 0;
var lati,longi;
timer_control = setInterval(req_control,15000)

    function onLocationFound(e) {

      if (current_position) {
          map.removeLayer(current_position);
      }
      var radius = e.accuracy / 2;
      current_position = L.marker(e.latlng).addTo(map).bindPopup("Test : {{ $car->test }}");
      lati = e.latlng.lat;
      longi = e.latlng.lng;
      $.get( "/trac/mobil?lati="+e.latlng.lat + "&longi=" + e.latlng.lng+"&car_id="+carid);
    }

    function onLocationError(e) {
      alert(e.message);
    }

    map.on('locationfound', onLocationFound);
    map.on('locationerror', onLocationError);
  
    function locate() {
      map.locate({setView: true, maxZoom: 16});
    }

    setInterval(locate, 10000);
  </script>

As for the route request:

<script type="text/javascript">
    $.post( "{{ route('example.route.request') }}",
          {
            car_id:data.car_id
          },
          ).done(function(data2) { 
            if(data2!=0 || data2!=2)
            {
              document.getElementById("address1").setAttribute("value", data.address1);
              document.getElementById("address2").setAttribute("value", data.address2);
              clearInterval(req_control);
              if (current_position) {
                map.removeLayer(current_position);
              }
              example_data = L.Routing.control({
                waypoints: [
                    L.latLng(lati,longi),
                    L.latLng(data2.lati,data2.longi)
                ]
            }).addTo(map);
            }
          });
  </script>

I want to use it as a navigation app. As you get closer to the target, the route should be updated and only 2 markers should be visible. The first marker should also show my current location. I get latitude and longitude information from the script code above, but it is not updated.

Thanks.

storedprocedure
  • 152
  • 1
  • 16

0 Answers0