Support

Account

Home Forums General Issues Google Map Default InfoWindow on Load Reply To: Google Map Default InfoWindow on Load

  • Hi @jomurgel,

    Thanks for the post.

    I would recommend you save your markers to an array and then trigger a click event on of one of them using google.maps.event.trigger(). An example of this would look like so:

    function initialize() {
    ...
    
        point = new google.maps.LatLng(55.660491,12.587087); createMarker(point, "<div class='infoWindow'>3</div>");
    
        google.maps.event.trigger(markers[1], 'click');
    }
    
    function createMarker(latlng, html, name, number) {
        var marker = new google.maps.Marker({
            position: latlng,
            map: map,
            title: name,
            //icon: iconBase + number + '.png'
            icon: iconBase
        });
    
        // added to collect markers
        markers.push(marker);
    
        google.maps.event.addListener(marker, 'click', function () {
            console.log('click event listener');
            infowindow.setContent(html);
            infowindow.open(map, marker);
            //map.setCenter(marker.getPosition());
    
            // corrected due to error
            map.setCenter(new google.maps.LatLng(55.678939, 12.568359)); 
        });
    }