Xub*_*tho 4 javascript google-maps twitter-bootstrap twitter-bootstrap-3
我想将地图添加到我的联系页面的“地图和方向”中。我正在逐步尝试使用Google地图嵌入程序,但没有用,因为我无法查看地图。我正在使用引导程序。
这是我的标记:
    <head>
      <script type='text/javascript' src="http://maps.googleapis.com/maps/api/js?sensor=false&extension=.js&output=embed"></script>
      <script>
    $(document).ready(function() {
        var myCenter=new google.maps.LatLng(45.992261, -123.925014);
        var marker=new google.maps.Marker({
            position:myCenter
        });
        function initialize() {
          var mapProp = {
              center:myCenter,
              zoom: 14,
              draggable: false,
              scrollwheel: false,
              mapTypeId:google.maps.MapTypeId.ROADMAP
          };
          var map=new google.maps.Map(document.getElementById("map-canvas"),mapProp);
          marker.setMap(map);
          google.maps.event.addListener(marker, 'click', function() {
            infowindow.setContent(contentString);
            infowindow.open(map, marker);
          }); 
        };
        $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
            initialize();
        });
    });
    </script>
   <style type="text/css">
        #map-canvas {
            height:500px;
         }
    </style>
  <head>
    <div class="tab-content">
        <div class="tab-pane fade" id="map">
            <div class="col-md-5">
                <h4 class="h4">Find Us at Google Map</h4>               
            </div>
            <div id="map-canvas" class="col-md-7">
            </div>
        </div>
    </div>
试试这个代码,它的引导正常工作
function initialize() {
            var mapOptions = {
                center: new google.maps.LatLng(28.1823294, -82.352912),
                zoom: 9,
                mapTypeId: google.maps.MapTypeId.HYBRID,
                scrollwheel: false,
                draggable: false,
                panControl: true,
                zoomControl: true,
                mapTypeControl: true,
                scaleControl: true,
                streetViewControl: true,
                overviewMapControl: true,
                rotateControl: true,
            };
var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
        }
google.maps.event.addDomListener(window, 'load', initialize);#contactform .btn:hover {
  background: rgba(9,8,77,0.7);
}
#map-canvas {
  width: 100%;
  height: 300px;
  margin-bottom: 15px;
  border: 2px solid #fff;
}<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
            
<div id="map-canvas"></div>
    
<!--Google Maps API-->
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDnycWatbGyK6ldFqErjFtko1yeMclNUOA&sensor=true"></script>请为Google地图使用正确的API,您可以从Google地图控制台中获取。
@ymakux的评论表示“最好使用内置类”,多年来我一直在搜寻SO,以期使Google Map能够很好地适应bootstrap div,您的答案是完美的!因此,对于像我这样的新手,使用Bopotstrap的地图,并使用Google在https://developers.google.com/maps/documentation/javascript/geolocation提供的示例代码
按照@ymakux的建议在div之前添加div,类似于:
<div class="embed-responsive embed-responsive-4by3">
<div id="map-container" class="embed-responsive-item">
<div id="map">
</div>
</div> 
</div>`
Joe*_*ell -1
您的引导元素阻止您的地图显示。
<div>        
  <div style="border: 1px solid red;">
      <h4 class="h4">Find Us at Google Map</h4>               
  </div>
  <div id="map-container">
    <script src="http://maps.google.com/maps/api/js?sensor=false"></script>
  </div>     
</div>
一点CSS
#map-container{
    height: 500px;
    width: 500px;
}
您的地图将随之显示。
我也不会将您的地图调用放在您的 HEAD 标签中。让页面加载,然后加载地图。
显示地图后,慢慢添加引导程序组件,因为它们可以使用 Google 地图做一些奇怪的事情。尤其是网格布局。如果您保持网格布局打开并且看不到地图,请调整浏览器的大小(单击角落并拖动它),您应该能够找到显示地图的最佳位置。
| 归档时间: | 
 | 
| 查看次数: | 36419 次 | 
| 最近记录: |