简体   繁体   中英

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;
}

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM