Adam91Holt
Adam91Holt

Reputation: 1058

Google Maps refreshing everytime mouse is clicked

http://task4adamholt.appspot.com/?guestbook_name=Cars

For some reason every time the mouse is clicked, whether it be on the table or the actual map itself it refreshes all the maps for some reason.

Does anyone have any idea why, it's really strange. The .js file includes the following function

function getLoc(lon,lat,id) {
    function initialize() {
        var mapProp = {
            center: new google.maps.LatLng(lat, lon),
            zoom: 12,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById(id), mapProp);
        var marker = new google.maps.Marker({
            position: new google.maps.LatLng(lat, lon),
            map: map,
            title: 'Sent Here!'
        });
    }
    google.maps.event.addDomListener(window, 'click', initialize);
    document.getElementById(id).style.display = 'block';
}

Upvotes: 0

Views: 60

Answers (1)

Eric Guan
Eric Guan

Reputation: 15982

This is the line that's causing the problem.

 google.maps.event.addDomListener(window, 'click', initialize);

It listens for a click on the window, and runs the functions whenever a click happens, refreshing the map. I would definitely change the 'click' event to something else, like DOM ready.

Upvotes: 1

Related Questions