google-maps-api-3 - 调整 infoWindow 框的大小 Google Maps API v3

标签 google-maps-api-3 infowindow

默认的 infoWindow 大小对我来说太大了。我希望它能小得多,但我不知道该怎么做。我尝试在我的 infoWindow 构造函数上设置 maxWidth 参数,如下所示

    var infowindow = new google.maps.InfoWindow({'maxWidth':'10px'});

并像这样设置 CSS 宽度

<style type="text/css">
#infoWindow {
    width: 10px;
}
</style>

但这似乎只是改变了文本换行的大小,而不是实际的框的大小。如何更改 infoWindow 框的大小?

这是我的代码。

<!doctype html>
<html lang="en">
<head>
    <title>jQuery mobile with Google maps - Google maps jQuery plugin</title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
    <style type="text/css">
    #infoWindow {
        width: 10px;
    }
    </style>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3&sensor=false&language=en"> </script>
    <script type="text/javascript">

    var cityList = [
    ['Chicago', 41.850033, -87.6500523, 1],
    ['Illinois', 40.797177,-89.406738, 2]
    ];

    var demoCenter = new google.maps.LatLng(41,-87);

    var map;
    function initialize()
    {
        map = new google.maps.Map(document.getElementById('map_canvas'), {
            zoom: 7,
            center: demoCenter,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        });
        addMarkers();
    }

    function addMarkers()
    {
        var marker, i;
        var infowindow = new google.maps.InfoWindow({'maxWidth':'10px'});
        for (i = 0; i < cityList.length; i++)
        {
            marker = new google.maps.Marker({
                position: new google.maps.LatLng(cityList[i][1], cityList[i][2]),
                map: map,
                title: cityList[i][0]
            });

            google.maps.event.addListener(marker, 'click', (function(marker, i) {
                var contentString = '<div id="infoWindow">'
                    +'<div id="bodyContent">'
                    +'<p>'
                    + "This location is:<br>"
                    + marker.title
                    +'</p>'
                    +'</div>'
                    + '</div>';
                return function() {
                    infowindow.setContent(contentString);
                    infowindow.open(map, marker);
                }
                })(marker, i));
            }
        }

</script>
    </head>
    <body onload="initialize()">
        <div id="basic-map" data-role="page">
            <div data-role="header">
                <h1><a data-ajax="false" href="/">jQuery mobile with Google maps v3</a> examples</h1>
                <a data-rel="back">Back</a>
            </div>
            <div data-role="content">
                <div class="ui-bar-c ui-corner-all ui-shadow" style="padding:1em;">
                    <div id="map_canvas" style="height:350px;"></div>
                </div>
            </div>
        </div>
    </body>
</html>

最佳答案

native 信息窗口有最小尺寸。如果它对您来说太大,您需要考虑使用替代解决方案,例如 infoBubbleInfoBox

关于google-maps-api-3 - 调整 infoWindow 框的大小 Google Maps API v3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12102285/

相关文章:

javascript - 谷歌地图 api 不显示

javascript - Google Maps Infobox Autopan 问题

c# - 滚动条不出现

javascript - 将 google maps InfoWindow 设置为超过 700px 宽度

javascript - 有没有办法在 Google Maps API 中使用 3D Views 或 3D Perspective?

php - 尝试从 mySQL 数据库中包含的城市创建经纬度数组

jquery - 使用 Toggle 时 Google map 无法完全展开

javascript - 将变量传递给 Javascript 中的 onclick 函数不起作用

android - 将自定义 INFOWINDOW 与 MySQL 结合使用

javascript - 谷歌地图调整大小不起作用