【问题标题】:Google Maps with Bootstrap (Class - thumbnail)带有 Bootstrap 的 Google 地图(类 - 缩略图)
【发布时间】:2015-10-07 01:28:40
【问题描述】:

我需要使用 Bootstrap 框架将 Google 地图 DIV 放入另一个 DIV。

但是我的代码不能正常工作。 Google Maps DIV 不在框架内(灰色框架)。

您建议进行哪些调整?任何建议将不胜感激。

下面是代码:

sn-p HTML(使用 Bootstrap 框架):

<div class="thumbnail">
   <img src="images/title2015.jpg" class="img-responsive">
   <div class="caption">

      <h4><span class="glyphicon glyphicon-map-marker"></span>&nbsp;Google Maps:</h4>

      <div id="map_canvas" name="map_canvas"></div>

   </div>
</div>

CSS:

#map_canvas{
    width: 100%;
    height: 260px;
    float: left;
    position: relative;
    background-color: #f0f0f0;
    overflow: hidden;
    -webkit-transform: translateZ(0);
}

Javascript:

<script>
    function initialize() {
        var map_canvas = document.getElementById('map_canvas');
        var myLatLng = new google.maps.LatLng(??.??????, ??.??????);
        var map_options = {
            center: myLatLng,
            zoom: 16,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }

        var map = new google.maps.Map(map_canvas, map_options);

        var marker = new google.maps.Marker({

            position: myLatLng,
            map: map,
            title: 'Localization'
        });
    }
    google.maps.event.addDomListener(window, 'load', initialize);
</script>

【问题讨论】:

    标签: jquery html css twitter-bootstrap google-maps


    【解决方案1】:

    问题来了:

    #map_canvas{
      float: left;
    }
    

    您无需在 map_canvas div 上设置“浮动”。删除它或将其设置为“无”。我还注释掉了其他一些看起来不必要的东西。

    https://jsfiddle.net/partypete25/j5pcptb4/1/

    【讨论】:

    • #partypete25,完美!我是后端开发人员(C#、C-ANSI、C++、SQL Server 等...)。在他的回复之后,我意识到我需要学习更多的前端技术(CSS、Javascript、jQuery、HTML 等......)。谢谢。
    【解决方案2】:

    在#map_canvas 之后添加一个清晰的 div

    CSS

      .clear
      { 
              Clear: both;
      }
    

    HTML

    <div class="thumbnail">
       <img src="images/title2015.jpg" class="img-responsive">
       <div class="caption">
    
          <h4><span class="glyphicon glyphicon-map-marker"></span>&nbsp;Google Maps:</h4>
    
          <div id="map_canvas" name="map_canvas"></div>
        <div class="clear"></div>
    
       </div>
    </div>
    

    或将 clearfix 类添加到缩略图 div

    <div class="thumbnail clearfix">
       <img src="images/title2015.jpg" class="img-responsive">
       <div class="caption">
    
          <h4><span class="glyphicon glyphicon-map-marker"></span>&nbsp;Google Maps:</h4>
    
          <div id="map_canvas" name="map_canvas"></div>
    
       </div>
    </div>
    

    【讨论】:

    • #alireza safian,完美!我是后端开发人员(C#、C-ANSI、C++、SQL Server 等...)。在他的回复之后,我意识到我需要学习更多的前端技术(CSS、Javascript、jQuery、HTML 等......)。谢谢。
    猜你喜欢
    • 2018-08-12
    • 2013-09-21
    • 2019-11-22
    • 2016-08-20
    • 1970-01-01
    • 2014-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多