2014-12-06 42 views
0

我想添加谷歌地圖在引導地圖,但它不適合我。當我點擊鏈接時,它會打開模式窗口,但地圖顯示不正常,之前工作正常,但我不知道現在發生了什麼。谷歌地圖不工作在引導模式

直播鏈接,link to site

這裏是我的代碼:

JS:

var map; 
myLatlng = new google.maps.LatLng(4.7123724,-74.0704297); 
function initialize() { 
     var mapOptions = { 
      center: myLatlng, 
      zoom: 18, 
      mapTypeControl: false, 
      center:myLatlng, 
      panControl:false, 
      rotateControl:false, 
      streetViewControl: false, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
     }; 
     map = new google.maps.Map(document.getElementById("map_canvas"), 
      mapOptions); 

     var contentString = '<div id="mapInfo">'+ 
     '<strong>Carrera 58 # 127-29</strong><br>' + 
     'Bogotá, Cundinamarca<br>'+ 
     'Colombia'+ 
     '</div>'; 

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

     var marker = new google.maps.Marker({ 
     position: myLatlng, 
     map: map, 
     title:"Carrera 58 # 127-29, Bogotá, Cundinamarca, Colombia", 
       maxWidth: 200, 
       maxHeight: 200 
     }); 



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

     google.maps.event.addDomListener(window, 'load', initialize); 

    //start of modal google map 
    $('#mapmodals').on('shown.bs.modal', function() { 
     google.maps.event.trigger(map, "resize"); 
     map.setCenter(myLatlng); 
    }); 
    //end of modal google map 

HTML:

<a href="#mapmodals" role="button" data-toggle="modal"><i class="icon"></i> Launch Map Modal</a> 

    <!-- MAP --> 
    <div class="modal fade" id="mapmodals"> 
    <div class="modal-dialog modal-lg"> 
     <div class="modal-content"> 
     <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> 
      <h4 class="modal-title" id="myCity">Carrera 58 # 127-29, Bogotá, Cundinamarca, Colombia</h4> 
     </div> 
     <div class="modal-body"> 
      <div class="map_container"> 
       <div id="map_canvas" class="map_canvas"></div> 
      </div> 
     </div> 
     <div class="modal-footer"> 
     </div> 
     </div><!-- /.modal-content --> 
    </div><!-- /.modal-dialog --> 
    </div><!-- /.modal --> 
+0

您是否嘗試過http://getbootstrap.com/getting-started/#third-parties? – cvrebert 2014-12-07 00:32:34

回答

4

觸發的resize -event地圖時態已打開:

jQuery('#mapmodals') 
.on('shown.bs.modal', 
     function(){ 
     google.maps.event.trigger(map,'resize',{}); 
     map.setCenter(myLatlng); 
    }); 
0

您的代碼不能正常工作了我,所以我補充

google.maps.event.addListener(marker, 'click', function() { 

    infowindow.setContent(contentString); 
    infowindow.open(map, marker); 

}); 

感謝,

0

添加這個jQuery插件

  1. http://maps.google.com/maps/api/js?sensor=false&libraries=places
  2. locationpicker.jquery.js
+0

雖然這個鏈接可能回答這個問題,但最好在這裏包含答案的重要部分並提供參考鏈接。如果鏈接頁面更改爲 – abarisone 2015-03-27 09:17:00

+0

好的鏈接,則僅鏈接答案可能會失效。謝謝丹麥:) – Atf 2015-03-27 10:31:31