Hi all,

I have a map that loads new pins from an XHR onload and then when the
user moves/zooms etc.

I'm coming from V2 where I used moveend without trouble. I have now
tried idle, (zoom_changed + center_changed) and bounds_changed; in all
cases I find that my new markers click event won't fire. I believe
this is because the events are being fired more than once. When I
remove the load data function call the onload markers have their click
events work fine.

I believe my scenario is common, if so what have I missed here? What
event should be used in this setup or have I gone wrong somewhere?

Thanks
Denis



var irelandDotCom = {};

function initMap() {
    var myOptions = {
        zoom: 8,
        center: new google.maps.LatLng(53.4095319, -7.9101563),
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        scrollwheel: false
    }
    irelandDotCom.map = new
google.maps.Map(document.getElementById("dynamicmap"), myOptions);
    irelandDotCom.geocoder = new google.maps.Geocoder();
    irelandDotCom.infoWindow = new google.maps.InfoWindow();
    irelandDotCom.markers = [];

    google.maps.event.addListener(irelandDotCom.map, "bounds_changed",
function() {
        loadData();
    });

    loadData();
}

function loadData() {
    $("#maploading").fadeIn();
    var requestUrl = "My AJAX request uri";
    $.ajax({
        url: requestUrl,
        cache: false,
        dataType: "jsonp",
        success: function(data) {
            var lastlatlng = "1";
            var currentlatlng = "0";

            if (irelandDotCom.markers) {
                for (marker in irelandDotCom.markers) {
                    irelandDotCom.markers[marker].setMap(null);
                }
            }

            for (amenity in data.Amenities) {
                var marker = new google.maps.Marker({
                    position: new
google.maps.LatLng(data.Amenities[amenity].Latitude,
data.Amenities[amenity].Longitude),
                    map: irelandDotCom.map,
                    title: data.Amenities[amenity].Name,
                    clickable: true,
                    icon: "pin.png"
                });
                irelandDotCom.markers.push(marker);
                addMarkersInfoWindow(amenity);
            }
        },
        error: function(e) {         }
    });
}


function addMarkersInfoWindow(pointer) {
    google.maps.event.addListener(irelandDotCom.markers[pointer],
'click', function() {
        markerClicked(irelandDotCom.markers[pointer]);
    });
}

function markerClicked(marker) {
    var content = "My content for a marker";
    irelandDotCom.infoWindow.setContent(content);
    irelandDotCom.infoWindow.open(irelandDotCom.map, 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.

Reply via email to