Subhashree Panda
Subhashree Panda

Reputation: 21

Stop InfoWindow on Google Maps showing on load

Hi I am trying to integrate gmap with my website.But by default the infowindow is opened.I want to open the infowindow after clicking on the markers.How to close the infowindow on page load?

function initialize() {
    if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map_canvas"));
        map.setCenter(new GLatLng(22.4642600, 70.0690540), 6);
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.addMapType(G_SATELLITE_3D_MAP);
        for (var i = 0; i < newpoints.length; i++) {
            var point = new GPoint(newpoints[i][1], newpoints[i][0]);
            var popuphtml = newpoints[i][4];
            var post_url = newpoints[i][5];
            var addr = newpoints[i][6];
            var marker = createMarker(point, newpoints[i][2], popuphtml, post_url, addr);
            map.addOverlay(marker);
        }
    }
}

function createMarker(point, icon, popuphtml, post_url, addr) {
    var popuphtml = '<div id="popup">' + popuphtml + '<div><a href=' + post_url + '>Link</a></div></div>';
    var marker = new GMarker(point);
    marker.openInfoWindowHtml(popuphtml);
    GEvent.addListener(marker, "click", function () {
        marker.openInfoWindowHtml(popuphtml);
    });
    return marker;
}

Upvotes: 2

Views: 643

Answers (2)

Manse
Manse

Reputation: 38147

Remove this line

marker.openInfoWindowHtml(popuphtml);

so it becomes

function createMarker(point, icon, popuphtml, post_url, addr) {
    var popuphtml = '<div id="popup">' + popuphtml + '<div><a href=' + post_url + '>Link</a></div></div>';
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function () {
        marker.openInfoWindowHtml(popuphtml);
    });
    return marker;
}

you were calling the openInfoWindowHtml method immediately ... now its only called when the click event of the marker occurs

Note

You are using Google Maps V2 ... this is the message from google related to V2

Note: The Google Maps Javascript API Version 2 has been officially deprecated as of May 19, 2010. The V2 API will continue to work as per our deprecation policy, but we encourage you to migrate your code to version 3 of the Maps Javascript API.

Upvotes: 1

snaderss
snaderss

Reputation: 139

remove the marker.openInfoWindowHtml(popuphtml); after var marker = new GMarker(point);

Upvotes: 0

Related Questions