繁体   English   中英

使用Google Maps Javascript API v3,如何在点击时生成默认的信息框?

[英]Using the Google Maps Javascript API v3, How do I produce the default infoboxes on click?

到目前为止,这就是我所拥有的。

function init_map() {
    var places = [
        { name: "Place 1", coords: new google.maps.LatLng(30.728752, -73.995525)},
        { name: "Place 2", coords: new google.maps.LatLng(30.733673, -73.990028)},
        { name: "Place 3", coords: new google.maps.LatLng(40.725778, -73.992249)}
    ]

    var myOptions = {
        zoom: 14,
        center: places[0].coords,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
    }

    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    for ( var x=0; x < places.length; x++ ){
        var place = places[x];
        var marker = new google.maps.Marker({
            position: place.coords,
            title: place.name,
            icon: icon,
            clickable: true,
            infowindow: new google.maps.InfoWindow({content:"hello world"})
        });
        marker.setMap(map);

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

我希望有一个默认的InfoWindow,而不是我自己的自定义窗口,您会在Google Maps上搜索地址时看到它。 这怎么可能?

您的默认Google内容是什么意思?

同样,最好只创建一个信息窗口对象,然后在标记之间共享它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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