I have an array filled with various coordinates and data entries. My goal is to create a polyline that connects all these coordinate points within the array. While I can successfully place markers and infowindows, I am encountering difficulty in generating the polyline.
I intend to iterate through the array using a loop, as I plan to utilize the same method for additional sets of coordinates in the future.
Below is the code snippet:
var places = [
['New Delhi', 28.6139587, 77.208684],
['Amritsar', 31.643628, 74.859624],
['Srinagar', 34.09, 74.79],
['Kargil', 34.55, 76.133333],
['Alchi', 34.2334, 77.1625],
['Leh', 34.145397, 77.567614]
];
for (var i = 0; i < places.length; i++){
var coords = new google.maps.LatLng(places[i][1], places[i][2]);
poly.push(coords);
}
console.log(poly);
var Itinerary = new google.maps.Polyline({
path: poly,
geodesic: true,
strokeColor: '#ffd500',
strokeOpacity: 1.0,
strokeWeight: 5
});
Itinerary.setMap(map);