Google Maps Polyline - How do I remove it?

前端 未结 5 979
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-17 17:34

So I checked previous questions regarding this, which all relate to V2, which is of no help.

So, I create two markers, save them in an array as markers[\"to\"] and m

5条回答
  •  渐次进展
    2021-01-17 18:19

    I don't see var before flightPath = new..., so I presume flightPath is a global variable.

    function route(){
       //flightPath.setMap(null); Doesnt't work!?
       for(var key in markers) {
           flightPlanCoordinates.push(markers[key].position);
       }
       if(flightPath) {//If flightPath is already defined (already a polyline)
           flightPath.setPath(flightPlanCoordinates);
       } else {
           flightPath = new google.maps.Polyline({
               path: flightPlanCoordinates,
               strokeColor: "#FF0000",
               strokeOpacity: 1.0,
               strokeWeight: 2
          });
          flightPath.setMap(map);//It's not necessary to setMap every time
       }
    
    }
    

提交回复
热议问题