当我打开infoWindow(UTF-8)时谷歌地图变得奇怪

las*_*emt 1 javascript google-maps

我正在使用Google地图进行新项目,但是当我打开一个项目时,我的地图变得怪异infoWindow.

见下图:

图片描述

有人认出这个问题吗?

这是我的地图初始化代码:

$(document).ready(function(){   

    function initialize() {
        var myLatlng = new google.maps.LatLng(59.398554, 5.486206);
        var mapOptions = {
            draggable: true, 
            zoomControl: true, 
            mapTypeControlOptions: {
                mapTypeIds: [google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.HYBRID]
            }, // here´s the array of controls
            disableDefaultUI: true, // a way to quickly hide all controls
            scrollwheel: false,
            zoom: 13,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }

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

        var contentString = '<div id="content">'+
            '<div id="siteNotice">'+
            '</div>'+
            '<h2 id="firstHeading" class="firstHeading">FjørSilkeBris</h2>'+
            '<div id="bodyContent">'+
            '<p>Førland, 5570 Aksdal</p>'+
            '<p>481 49 246 (Mobil)</p>'+
            '<p>Facebook: <a href="https://www.facebook.com/FjorSilkeBris">FjørSilkeBris på facebook.</a></p>'+
            '</div>'+
            '</div>';

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

        var marker = new google.maps.Marker({
            position: myLatlng,
            map: map,
            title:"Fjørsilkebris"
        });

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

    window.onload = function () {
        initialize();
    }
});
Run Code Online (Sandbox Code Playgroud)

小智 11

我有同样的问题.

问题是,页面上的某些CSS很可能将img元素的max-width属性设置为100%.这打破了地图上的infowindow的css.

您可以做的是覆盖地图的画布div示例的img max-width:

#divMap img { max-width: none; }
Run Code Online (Sandbox Code Playgroud)

这对我有用

  • 这应该是公认的答案.它实际上提供了一个解决方案,而不仅仅是指出问题 (2认同)