Dear All, This thread was very useful. I was also having similar problem. Once I declared a function and moved the rendering of polyline to the function and used local variable, all my routes were rendered with appropriate colour.
Thanks, Yogalakshmi. On Friday, November 12, 2010 at 8:04:33 PM UTC+5:30, Canam Group wrote: > > Hi, > > I'm in the process of migrating our Map application from V2 to V3 (3.2). > Sorry, I can't post a link to our map cause we use it internally (don't > worry, we paid for this). > > I had a loop that read LatLng and put them in a array to display as a > Polyline on the map. > I then set the length of my array to 0 and then fill it again in the loop > with other LatLng to display another Polyline... and so on (many times). > > It was working fine in V2, but not in V3. > Since my code is complex, I tried to write the simpliest code possible to > demonstrate my issue: > > function setPolyline(points) { > var polyline = new google.maps.Polyline({ > path: points, > strokeColor: '#FF0000', > strokeOpacity: 0.5, > strokeWeight: 2 > }); > polyline.setMap(map); > } > > var mapDiv = document.getElementById('map'); > var mapCenter = new google.maps.LatLng(0,0); > var mapOptions = { > zoom: 2, > center: mapCenter, > backgroundColor: '#E1E1E1', > mapTypeId: google.maps.MapTypeId.ROADMAP > } > map = new google.maps.Map(mapDiv, mapOptions); > > var points=[]; > points[0]=new google.maps.LatLng(-35, 71); > points[1]=new google.maps.LatLng(-36, 75); > points[2]=new google.maps.LatLng(-37, 91); > setPolyline(points); > > points.length=0; > points[0]=new google.maps.LatLng(-31, 71); > points[1]=new google.maps.LatLng(-32, 75); > setPolyline(points); > > What happens is that only the second Polyline is shown (and not the first > one). > To make it works, I have to either use a different variable name (points1, > points2, points3, ...) which I can't use because my code is normally in a > loop or re-declare my variable each time in the loop instead of before it > (var points=[] before each Polyline and remove the points.length=0 line). > > Maybe I'm missing something about JavaScript, but I usually declare my > variable outside the loop (before) once and use it inside the loop. > > What am I doing wrong? > Can someone help? > > Thanks! > -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-maps-js-api-v3+unsubscr...@googlegroups.com. To post to this group, send email to google-maps-js-api-v3@googlegroups.com. Visit this group at https://groups.google.com/group/google-maps-js-api-v3. For more options, visit https://groups.google.com/d/optout.