sg

Salı, Aralık 13, 2005

data.xml, info windows and separating functions


Through these forums, I've identified my problem and found a solution.
However, I'm new to this and I don't understand how to implement the
solution.

I'm using an xml file to store several markers. When clicked, the
markers open up an info-window. The problem is that regardless of
which marker I click, the last one in the xml file appears. Another
poster had this problem and was given the following advice, which
apparently worked.

>>when i click on any of the markers it brings me
>>to the last one on the XML file

>It's because you inlined the function-closure instead of putting it in
>a separate function. The function-closure must be created inside a separate
>function or else it doesn't work properly. Doesn't make sense but it's
>a fact nevertheless.

That's great, but I don't know what it means. Can anyone help me out?

Here's my code:

var request = GXmlHttp.create();
request.open("GET", "redstops.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = GXml.parse(request.responseText);
var markers = xmlDoc.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var point = new
GPoint(parseFloat(markers[i].getAttribute("lng")),
parseFloat(markers[i].getAttribute("lat")));
var marker = new GMarker(point, redIcon);
var html = markers[i].getAttribute("description");
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html); });
map.addOverlay(marker);
}
}
}
request.send(null);

and my xml file looks like this:

<markers>
<marker lat="37.245037" lng="-121.870265" description="Almaden Light
Rail Station" />
<marker lat="37.253748" lng="-121.866875" description="Oakridge Light
Rail Station"/>
</markers>

Adam

0 Comments:

Yorum Gönder

<< Home


Komik Videolar   islam  şarkı sözleri  yemek tarifleri  gelibolu  huzur   sağlık