On Nov 17, 7:01 am, Canam Group <canamgr...@gmail.com> wrote: > John, > I might be wrong, but I don't think it's because you used a function > (or closures) that you solved the problem... but because you re-declare > your array each time in the loop (inside a function in your example): > > function addLineWithClosure(coordinates,i) { > var points = coordinates.split(' ',2); > var p0 = points[0].split(',',3); > var p1 = points[1].split(',',3); > var linePos = new Array(); > var lineOptions = { strokeColor: "#FF0000", > strokeOpacity: 1.0, > strokeWeight: 2, > zIndex: i > > }; > > linePos[0] = new google.maps.LatLng(Number(p0[1]),Number(p0[0])); > linePos[1] = new google.maps.LatLng(Number(p1[1]),Number(p1[0])); > > var line = new google.maps.Polyline(lineOptions); > line.setPath(linePos); > line.setMap(map); > > } > > for (i=0; i < placemarks.length; i++) { > markName = > placemarks[i].getElementsByTagName("name" )[0].childNodes[0].nodeValue; > coordinates = > placemarks[i].getElementsByTagName("coordinates")[0].childNodes[0].nodeValu e; > > addLineWithClosure(coordinates,i); > > } > > You re-declare your array each time in the loop (in your function): > var linePos = new Array(); > > It's exactly what I'm experiencing. > If I re-declare my array before adding each polyline (in a loop or > not), it works: > var points=[]; > > If I declare my array once, and empty it before using it again: > points.length=0; > > It doesn't work the first time... but it works every time after (if > just the polylines are reloaded and not the whole page). > I think we are experiencing the same issue (and I've found other people > on the web with that problem as well). > > Now, until I find a better solution, I re-declare my array each time in > the loop (or I could use a function like you that create a new array > every time) but I still don't understand why it behaves like this with > polylines and not with markers... > > Larry, > Mike Williams' tutorials helped me a lot when I was designing > my application with v2 last year. > I hope he'll do the same with v3 :)
He posted a message to one of the groups the said his take is that Google's tutorials and examples cover everything a tutorial from him would cover (my words, you can probably find the thread if you search). I know that I am still pointing people to his v2 tutorial for help solving problems in v3 (like the dreaded pitfall #3, solved by function closure) and his "Javascript Concepts" pages. -- Larry > > Thanks to both of you! -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to google-maps-js-api...@googlegroups.com. To unsubscribe from this group, send email to google-maps-js-api-v3+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.