Here is the JSFiddle Demo :
First we create a global variable for storing polyline points:
var flightPlanCoordinates = [];
The problem is that you do not feed the polyline with more than one Lat Lng. So, in principle, this is not drawing a polyline, because to create it, it has only one Lat Lng. You need more than one Lat Lng to create some kind of string. So we created a global array called flightPlanCoordinates to track the Lat Lng polyline and push the Lat Lng locations to it in the for loop. At the end of the for loop, we create an overlay of the polyline and set it with the current map:
function see() { var locations = new Array(3); //(<%= count%>); for (i = 0; i < locations.length; i++) { locations[i] = new Array(2); //This one is wrong!! (<%= count%>); } for (i = 0; i < locations.length; i++) { locations[i][0] = 18.9 + i / 100; locations[i][1] = 72.8 + i / 100; } var i; var infowindow = new google.maps.InfoWindow(); var marker; for (i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i][0], locations[i][1]), map: map }); //pushing Lat Lng to use to create polyline flightPlanCoordinates.push(new google.maps.LatLng(locations[i][0], locations[i][1])); } var flightPath = new google.maps.Polyline({ path: flightPlanCoordinates, strokeColor: "#FF0000", strokeOpacity: 1.0, strokeWeight: 2 }); flightPath.setMap(map); }
In addition, your information window does not really have anything to show. To open it, there is no associated w / marker event event.
source share