Google Maps Polyline - How do I remove it?

前端 未结 5 921
佛祖请我去吃肉
佛祖请我去吃肉 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:15

    flightPath is just an array of LatLng objects, not individual polylines. I think you probably need a separate array for the polylines, which you can then loop over to remove them all. Create a global array line.

     var line = [];
     flightPath = new google.maps.Polyline({
            path: flightPlanCoordinates,
            strokeColor: "#FF0000",
            strokeOpacity: 1.0,
            strokeWeight: 2
        });
     line.push(flightPath);
    

    Now you are pushing all the polyline objects into an array line. You can make it invisible or remove it from the map by looping it like this:

    for (i=0; i

提交回复
热议问题