title: Google Maps Polyline: Mark the two Polyline coordinates that contain the clicked LatLng
body: <p>I have a problem in polyline of google maps.</p>
  
  <p>I have a polyline from one points to another point. When I click on the polyline, I need the latitude and logitude of the two ends.</p>
  
  <p>Please can anyone help me?</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta name="viewport" content="initial-scale=1.0, user-scalable=no"/&gt;
  &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8"/&gt;
  &lt;title&gt;Google Maps JavaScript API v3 Example: Geocoding Simple&lt;/title&gt;
  &lt;link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" /&gt;
  &lt;script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt; 
  function initialize()
  {   
      var myLatLng = new google.maps.LatLng(0, -180);   
      var myOptions = {zoom: 2,center: myLatLng,mapTypeId: google.maps.MapTypeId.TERRAIN};  
      var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
      var flightPlanCoordinates = [   new google.maps.LatLng(17.772323, 78.214897),
                                      new google.maps.LatLng(28.46758, 78.027892),
                                      new google.maps.LatLng(29.46758, 88.027892),
                                      new google.maps.LatLng(20.46758, 97.027892),
                                      new google.maps.LatLng(17.772323, 78.214897)
                                  ]; 
      var flightPath = new google.maps.Polyline({path: flightPlanCoordinates,strokeColor: "#FF0000",strokeOpacity: 1.,strokeWeight: 10});
      var infowindow = new google.maps.InfoWindow();
      google.maps.event.addListener(flightPath, 'click', function() 
                                                          {        
                                                          //attached click event now do your logic here       
                                                              this.getPath().forEach(function(el, index)
                                                                                      {          
                                      //infowindow.setContent('Point ' + index + ' : Latitude = ' + el.lat() + ' | Longitude = ' + el.lng());         
                                                  alert('Point ' + index + ' : Latitude = ' + el.lat() + ' | Longitude = ' + el.lng());
                                                                                      });
                                                          });
      flightPath.setMap(map);
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onload="initialize()"&gt;
      &lt;div id="map_canvas" style="width=100%; height:60%"&gt;&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>