地图和框架边框之间的差距

时间:2015-03-18 20:53:23

标签: javascript html google-maps

我已经在地图中创建了一个地图。当我用图片填充框架时,它会完全填充整个框架但是当我在框架中插入地图时,它会在框架边框和地图之间留下一个小间隙。我试图改变地图高度,但它没有帮助。我有两个问题:

  1. 为什么代码表现得那样?
  2. 如何正确填充地图     整个框架?
  3. 图片: enter image description here

    代码:

     <script type="text/javascript">
        //<![CDATA[
    
    
        var customIcons = {
          restaurant: {
            icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png'
          },
          bar: {
            icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png'
          }
        };
    
        function load() {
          var map = new google.maps.Map(document.getElementById("map"), {
            center: new google.maps.LatLng(47.6145, -122.3418),
            zoom: 13,
            mapTypeId: 'roadmap'
            //google.maps.event.trigger(map, 'resize'); 
          });
          var infoWindow = new google.maps.InfoWindow;
    
          // Change this depending on the name of your PHP file
          downloadUrl("genxml.php", function(data) {
            var xml = data.responseXML;
            var markers = xml.documentElement.getElementsByTagName("marker");
            for (var i = 0; i < markers.length; i++) {
              var name = markers[i].getAttribute("name");
              var address = markers[i].getAttribute("address");
              var type = markers[i].getAttribute("type");
              var point = new google.maps.LatLng(
                  parseFloat(markers[i].getAttribute("lat")),
                  parseFloat(markers[i].getAttribute("lng")));
              var html = "<b>" + name + "</b> <br/>" + address;
              var icon = customIcons[type] || {};
              var marker = new google.maps.Marker({
                map: map,
                position: point,
                icon: icon.icon
              });
              bindInfoWindow(marker, map, infoWindow, html);
            }
          });
        }
    
        function bindInfoWindow(marker, map, infoWindow, html) {
          google.maps.event.addListener(marker, 'click', function() {
            infoWindow.setContent(html);
            infoWindow.open(map, marker);
          });
        }
    
        function downloadUrl(url, callback) {
          var request = window.ActiveXObject ?
              new ActiveXObject('Microsoft.XMLHTTP') :
              new XMLHttpRequest;
    
          request.onreadystatechange = function() {
            if (request.readyState == 4) {
              request.onreadystatechange = doNothing;
              callback(request, request.status);
            }
          };
    
          request.open('GET', url, true);
          request.send(null);
        }
    
        function doNothing() {}
    
        //]]>
    
      </script>
    

    map.css

    #map {width: 100%;height: 98vh;margin: 0px;padding: 0px;}
    

1 个答案:

答案 0 :(得分:0)

我希望通过添加margin-top:-5px;或任何其他适合您的负数,将填补顶部的空白。 here是应用于div

的示例