Google Map Infowindow not showing properly

寵の児 提交于 2019-12-17 02:37:41

问题


The infowindow is not showing properly on my map when clicking on a marker. The website is here.

You'll also notice the map control isn't properly displayed either.

    var map;
    var locations = <?php print json_encode(di_get_locations()); ?>;
    var markers = []
    jQuery(function($){
        var options = {
            center: new google.maps.LatLng(51.840639771473, 5.8587418730469),
            zoom: 8,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        map = new google.maps.Map(document.getElementById("map_canvas"), options);

        for (var i=0; i < locations.length;i++) {
            makeMarker(locations[i]);
        }
        centerMap();

    });
    function makeMarker(location) {
        var markerOptions = {map: map, position: new google.maps.LatLng(location.lat, location.lng)};
        var marker = new google.maps.Marker(markerOptions);
        markers.push(marker);
        var content = '';

        var infowindow = new google.maps.InfoWindow(
          { content: "test",
            size: new google.maps.Size(50,50),
            disableAutoPan : true
          });


        google.maps.event.addListener(marker, 'click', function(e) {
            infowindow.open(map,marker);
        });
    }
    function centerMap() {
      map.setCenter(markers[markers.length-1].getPosition());
    }

Note: I'm using Google Maps JS V3.


回答1:


The issue is forced by this format inside style.css:

img {
    height: auto;
    max-width: 100%;/* <--the problem occurs here*/
}

Add this to the end of your style.css to apply the default-value for images inside the map:

#map_canvas img{max-width:none}



回答2:


The issue can be you are using img{ max-width: 100%; } as universal.

Try this one in to your css

.gmnoprint img {
    max-width: none; 
}



回答3:


In Magento case google map zoom controls were not displaying because of conflict with PROTOTYPE library.




回答4:


I solved the problem with :

.gmnoprint img {
    max-height: none;  
}

instead of max-width.

Thanks




回答5:


I had tried most of internet answers but that are not useful (not working), I had added custom css and map zoom control are visible also enable marker click. This answer also useful for this question


    .gmnoprint{
        display: block !important
    }
    .gmnoprint.gm-bundled-control.gm-bundled-control-on-bottom {
        display: block !important;
    }
    .gm-tilt {
        display: none;
    }
    .gm-iv-address{
        height: 56px;
    }



来源:https://stackoverflow.com/questions/9663375/google-map-infowindow-not-showing-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!