views:

15

answers:

1

Hi all,

I've got the following problem with Googlemaps.

I've created a createMarker function which returns a marker which i publish with addOverlay(). This works perfect, the marker get shown but the only problem is the click event voor the marker, i want a infowindow which is populated with the 'i want this text to be published' text, instead it gets populated with a var called html which i set in the beginning of my code (var html = 'test';), i received earlier a message with 'html is not defined', this is why is set the html var. Every infowindow has the text 'test' in it. I've tried using updateInfoWindow() but that doen't work, anyone familiar with this problem? I can supply you with the full source but i think the createMarker function should be enough.

function GM_load() {
   map = new GMap2(document.getElementById("map"));
   map.addControl(new GSmallMapControl());
   map.addControl(new GMapTypeControl());
   map.enableScrollWheelZoom(); 
   map.setMapType(G_HYBRID_MAP);
   geocoder = new GClientGeocoder(); 
   GM_showItems();
}    


function GM_showItems() {
   GDownloadUrl("modules/Googlemaps/ajax/getItems.php", function(data, responseCode) {
        var xml = GXml.parse(data);
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {


            //start 
            var itemid = markers[i].getAttribute('id');
            var title = markers[i].getAttribute('name');
            var address = markers[i].getAttribute('address');
            var city = markers[i].getAttribute('city');
            var x = 0;
            if (geocoder) {

                geocoder.getLatLng(address + ' ' + city,
                    function(point) {
                        if (!point) {
                            alert(address + ' ' + city + " not found");
                        } else {
                            x = x+1;
                            Marker = createMarker(point, x);
                            map.addOverlay(Marker);
                        }
                    }
                );
            }

        }

    });
}




function createMarker(latlng, number) {
    var marker = new GMarker(latlng);
    marker.value = number;
    GEvent.addListener(marker,"click", function() {
        map.openInfoWindowHtml(latlng,'i want this text to be published');
    });

    return marker;
}
A: 

Solved.

I overwrite var html. not perfect but it works.

Tim