title: how to connect multiple markers to a single location using javascript
body: <p>I wanted to connect multiple markers to a single location using javascript.</p>
  
  <p>I have written the code below and I am getting markers that are getting connected sequentially (as in the image provided).</p>
  
  <p>FYI, I am a beginner in working with javascript and google maps.</p>
  
  <p>I wanted to connect the markers to the following location <strong>['134.56.32.13',19.0760,72.8777]</strong> <br>
  where, <br>
  '134.56.32.13' is the example IP address<br>
  19.0760 is the latitude<br>
  72.8777 is the longitude.</p>
  
  <p>This is a link i found helpful in connecting the locations -
  <a href="https://stackoverflow.com/questions/43291764/connect-multiple-markers-with-polyline">Connect Multiple markers with polyline</a></p>
  
  <pre><code>var locations = [
    ['123.134.67.145', 22.5726, 88.3639],
    ['140.91.57.132', 28.7041, 77.1025],
    ['110.191.167.130', 13.0827, 80.2707],
    ['192.168.151.151', 12.9716, 77.5946]
  ];
  
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: new google.maps.LatLng(19.75, 77.94),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });
  
  var infowindow = new google.maps.InfoWindow();
  
  var marker, i;
  var flightPlanCoordinates = [];
  for (i = 0; i &lt; locations.length; i++) {
    marker = new google.maps.Marker({
      position: new google.maps.LatLng(locations[i][1], locations[i][2]),
      map: map
    });
    flightPlanCoordinates.push(marker.getPosition());
    google.maps.event.addListener(marker, 'click', (function(marker, i) {
      return function() {
        infowindow.setContent(locations[i][0]);
        infowindow.open(map, marker);
      }
    })(marker, i));
  
    var flightPath = new google.maps.Polyline({
      map: map,
      path: flightPlanCoordinates,
      strokeColor: "#ff0000",
      strokeOpacity: 1.0,
      strokeWeight: 2
    });
    flightPath.setMap(map);
  }
  </code></pre>
  
  <p>The markers are getting connected sequentially.This is the image.</p>
  
  <p><a href="https://i.stack.imgur.com/vHsg8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vHsg8.png" alt="enter image description here"></a></p>
  
  <p>This is how the output should look like</p>
  
  <p><a href="https://i.stack.imgur.com/Ap1Ir.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ap1Ir.png" alt="enter image description here"></a></p>