I am having a problem with the following code. I am pulling marker
location data (adddress) from an XML file along with a name for each
marker (Company). I want to show the respective company attribute from
the XML file in a popup window (openInfoWindowHtml) and I thought the
code below should do the trick, however it is for some reason printing
the name of the last company in every popup window.
Any thoughts as to what I have done wrong? I am a bit of a javascript
novice and tried everything I can think of.
var map;
var geocoder;
var xml;
var markers;
var address;
var name;
function load()
{
map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(22.59372606392931, 27.7734375), 2);
map.addControl(new GSmallMapControl());
geocoder = new GClientGeocoder();
GDownloadUrl("./maps/data.xml", function(data) {
xml = GXml.parse(data);
markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
address = markers[i].getAttribute("address");
name = markers[i].getAttribute("name");
geocoder.getLocations(address, addToMap);}
});
}
function addToMap(response)
{
place = response.Placemark[0];
point = new GLatLng(place.Point.coordinates[1],
place.Point.coordinates[0]);
map.addOverlay(createMarker(point, "<div class='google_popup'><b>" +
name + "</b></b>"));
}
function createMarker(point, html) {
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.