can anyone please help me with this javascript for drawing polyline in googlemap....i've drawn two polyline in google-map with markers, but the problem is when i click the marker the details is printing only on one marker...... also the details is not fully printed inside the information window
my code is as given below
$(function(){
 var map    = new google.maps.Map(document.getElementById("map"), {
                  center: new google.maps.LatLng(11.275387916698238, 75.8015380957031),
                  zoom: 12
               }),
     routes = [{origin:'p t usha road, kozhikode', 
               destination:'cooperative hospital, eranjipalam, kozhikode'
               }, 
               {origin:'IIM, Kozhikode',
               destination:'VELLIMADUKUNNU, KOZHIKODE'
               }
              ],
     rendererOptions = {
                preserveViewport: true,
                map:map,
                polylineOptions:{strokeColor:'#FF3300',
                                 strokeWeight: 10},        
                suppressMarkers:true,
                routeIndex:0
              },
     directionsService = new google.maps.DirectionsService();
      $.each(routes,
        function(i,obj){//<--anonymous function
        var request = {
                origin: obj.origin,
                destination: obj.destination,
                travelMode: google.maps.TravelMode.DRIVING
              },
            directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions);
            directionsService.route(request, function(result, status) {
              if (status == google.maps.DirectionsStatus.OK) {
var lat = result.routes[0].legs[0].start_location.lat();
var lon = result.routes[0].legs[0].start_location.lng();
    var lat1 = result.routes[0].legs[0].end_location.lat();
var lon1 = result.routes[0].legs[0].end_location.lng();             
                  try{  
                  marker = new google.maps.Marker({
    position: new google.maps.LatLng(lat, lon),
        map: map
      });
                                                   var iws = new google.maps.InfoWindow({
       content: "Home For Sale"
     });
     google.maps.event.addListener(marker, "click", function (e) { iws.open(map, marker); });
                  }catch(e){alert(e)}
                       try{  
                  marker = new google.maps.Marker({
    position: new google.maps.LatLng(lat1, lon1),
        map: map
      });
                            var iw = new google.maps.InfoWindow({
       content: "Home For Sale"
     });
     google.maps.event.addListener(marker, "click", function (e) { iw.open(map, marker); });
                  }catch(e){alert(e)}
                  directionsDisplay.setDirections(result);
              }
            });  
        });});
