Google会在加载时打开infowindow

时间:2015-02-09 16:58:44

标签: javascript google-maps google-maps-api-3

您好我正试图在页面加载时打开我的谷歌mapps infowidnow。我一直试图弄清楚如何做到这一点,但无济于事。我想知道是否有人可以看一眼并将我推向正确的方向?

谢谢

这是我的代码:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {

    var latlng = new google.maps.LatLng(53.855475, -1.605927);
    var settings = {
        zoom: 16,
        scrollwheel: false,
        center: latlng,
        mapTypeControl: true,
        mapTypeControlOptions: {
            style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
        },
        navigationControl: true,
        navigationControlOptions: {
            style: google.maps.NavigationControlStyle.SMALL
        },
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var contentString = '<div id="content">' +
        '<div id="siteNotice">' +
        '</div>' +
        '<h1 id="firstHeading" class="firstHeading"></h1>' +
        '<div id="bodyContent">' +
        '<p></p>' +
        '</div>' +
        '</div>';

    var infowindow = new google.maps.InfoWindow({
        content: contentString
    });


    var map = new google.maps.Map(document.getElementById("map_canvas"), settings);
    var companyPos = new google.maps.LatLng(53.855475, -1.605927);
    var companyMarker = new google.maps.Marker({
        position: companyPos,
        map: map,
        title: "Some title"

    });
    google.maps.event.addListener(companyMarker, 'click', function() {
        infowindow.open(map, companyMarker);
    });

}

0 个答案:

没有答案