On Jun 5, 9:23 am, Nick <livingxsacrif...@gmail.com> wrote: > ok heres a new version of my map which loads the data in from the XML > file. > > http://www2.stetson.edu/media/map/TabTest.html > > now theres an issue with the info window popping up at its appropriate > marker. Whichever marker you click the info window pops up in the > same location every time. > > any ideas on how to fix this?
add this line to the beginning of createTabbedMarker: var marker; so you get function closure on the marker variable... -- Larry > > On May 28, 2:05 pm, "geocode...@gmail.com" <geocode...@gmail.com> > wrote: > > > > > On May 28, 10:35 am, Nick <livingxsacrif...@gmail.com> wrote: > > > > ok. what you are saying makes perfect sense I just don't know how to > > > fix the problem. > > > this is what I have so far. > > > > GDownloadUrl("markerdata.xml", function(data) { > > > varxml= GXml.parse(data); > > > var markers =xml.documentElement.getElementsByTagName > > > ("marker"); > > > What I usually do is add a line here: > > GLog.write("processing "+markers.length+" markers"); > > > > for (var i = 0; i < markers.length; i++) { > > > var tabinfo = markers[i].getElementByTagName > > > ("tab"); <------------ this is comes up as an error > > > in my console saying that markers[i] is not a function. how would I > > > define it as a function? > > > The function is getElementsByTagName (notice the extra "s"), it > > returns an array of elements. > > > -- Larry > > > > var label = markers[i].getAttribute("label"); > > > var tabs = markers[i].getAttribute("tabs"); > > > var tabs = new Array(); > > > var type = markers[i].getAttribute("type"); > > > var point = new GLatLng(parseFloat(markers[i].getAttribute > > > ("lat")), > > > parseFloat(markers[i].getAttribute > > > ("lng"))); > > > var marker = createTabbedMarker(point, label, tabs, type); > > > map.addOverlay(marker); > > > } > > > if (tabInfo.length > 0) { > > > for (var j = 0; j < tabInfo.length; j++) { > > > var tabLabel = GXml.value(tabInfo > > > [j].getElementsByTagName("label")[0]); > > > var tabHtml = '<div style="height:350px; > > > overflow:auto"><b>' + label + '</b><br>' + GXml.value(tabInfo > > > [j].getElementsByTagName("contents")[0]) + '</div>'; > > > tabs.push(createTabbedMarker(tabLabel,tabHtml)); > > > } > > > > Line 5 comes up as an error in my console saying that markers[i] is > > > not a function. how would I define it as a function? And am I headed > > > in the right direction here? > > > > On May 27, 4:22 pm, Rossko <ros...@culzean.clara.co.uk> wrote: > > > > > > I found that error in my console as well. I am not sure how to fix it > > > > > though. Could you give me an example? > > > > > Every time I try to move my code around my map doesn't appear when I > > > > > run it. > > > > > Well, moving chunks of code around at random won't fix it, you have to > > > > look at what it does and think about what you'd like it do. > > > > Set aside the checkboxes issue for now - first get theXMLdisplaying > > > > on the map. Run - walk stuff. > > > > > Start by actually looking at the code you have, and thinking through > > > > it - > > > > > GDownloadUrl("markerdata.xml", function(data) { > > > > varxml= GXml.parse(data); > > > > var markers =xml.documentElement.getElementsByTagName("marker"); > > > > > That fetches theXMLand extracts all theXMLmarker sections > > > > > for (var i = 0; i < markers.length; i++) { > > > > var label = markers[i].getAttribute("label"); > > > > ... > > > > map.addOverlay(marker); > > > > } > > > > > That's a loop that scans through theXMLelements, extracts some > > > > data , makes some markers. Fine so far. > > > > > Next ... > > > > var point = new GLatLng(lat,lng); > > > > > What's that? What are lat and lng, you haven't defined them anywhere? > > > > > Next ... > > > > tabinfo = markers[i].getElementByTagName("tab"); > > > > > What is i ? We did define a variable i earlier and used it in the > > > > loop. It'll have been left pointing just beyond the lastXMLmarker. > > > > Looking at the next lines we can see that this code section is meant > > > > to read the tabs values for eachXMLmarker. It's not going to do > > > > that because i only ever points beyond the lastXMLmarker, where the > > > > previous loop left it pointng, and there's nothing to make it try more > > > > than once anyway. > > > > > This whole section needs to be inside the for-loop that was finished > > > > earlier, don't you think? > > > > That way, as eachXMLmarker was read you would also read its > > > > associated tabinfo. And then go round the loop to do the next one. > > > > > Going back to > > > > var point = new GLatLng(lat,lng); > > > > that'll never work because we have no lat or lng variable defined. > > > > But .. looking inside the previous for-loop, that already handles the > > > > required position of the markers it makes. Looking at the code > > > > afterwards (the tabs-reading section that needs to be moved inside the > > > > loop), that doesn't use a variable 'point' at all. The whole line is > > > > redundant (leftover from some previous work I expect) and needs taking > > > > out. > > > > > cheers, Ross K- Hide quoted text - > > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Google Maps API" group. To post to this group, send email to Google-Maps-API@googlegroups.com To unsubscribe from this group, send email to google-maps-api+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/Google-Maps-API?hl=en -~----------~----~----~----~------~----~------~--~---