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
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
}
}