Home » Php » How to add marker only after drawing the poly line is complete

How to add marker only after drawing the poly line is complete

Posted by: admin October 26, 2017 Leave a comment

Questions:

I am drawing the path of a vehicles’s past data on a google map. I have an array of lat lang along with the ignition status of the vehicle. Now my issue is that i have to add a marker at every ignition off and continue drawing poly line(animate by extending poly line) i am able to draw poly line and add marker but markers are getting added even before the start of poly line drawing. My goal is to start drawing poly line add marker at sop continue drawing. iam providing example code similar to the logic i have implemented, i need a trigger to add marker after drawing polyline.

function to extend polyline with time delay 
function draw(){
      var latlngsArray=array[{lat,lng,ignition},{lat,lng,ignition},...];
        for(var i=0; i<=latlangsArray.length; i++){
         var currentLatLng=new google.maps.LatLng(latlngsArray[i]['lat'], latlngsArray[i]['lng']);
         if(latlngsArray['ignition']==1){
           animateMarker(index,map,latlng);
         }else{
               var stopPointMarker = new google.maps.Marker({
                                    position: currentLatLng,
                                    map: map,
                                    });
         }
        }

}

//animation function
        function animateMarker(index,map,currentPosition)
        {
           setTimeout(function () {
               flightPath.getPath().push(currentPosition);// extend the polyline
               flightPath.setMap(map);// set polyline on map
               marker.setPosition(currentPosition);
               map.panTo(currentPosition);
           }, 200 * index);
       }

I have not provided map , marker , polyline definitions. i need those stop markers to be added in synchronisation with polyline drawing.. i hope iam clear in explaining my requirement.Any help is appreciated, thanks in advance.

Answers: