2017-04-03 19 views
0

我有一個初學者很難讓谷歌地圖在Rails中以Bootstrap模式顯示。谷歌地圖在Rails中的基本設置引導模式

Application.html.erb

<%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=AIzaSyCFm7OzAKuPbEa48b_aZ4S6JqMGVUCwwFs&callback=initMap", async: true, defer: true %> 

而在模態部分:

<div id="map"></div> 

<script> 
    var map; 
    function initMap() { 
    map = new google.maps.Map(document.getElementById('map'), { 
     center: {lat: -34.397, lng: 150.644}, 
     zoom: 8 
    }); 
    } 
</script> 

在頁面加載在控制檯中的錯誤是:

"initMap is not a function" 
name: "InvalidValueError" 

對此我必須承擔這是因爲initMap隱藏在未加載的Modal中。任何提示解決方案將不勝感激,我一直在研究它幾個小時。

編輯:...只是一個方面的評論,我知道這是另一個問題,但我以前有谷歌的地方自動完成安裝和工作,我拿出去谷歌地圖工作,因爲它給了一個錯誤(有2谷歌apis加載)。以前的谷歌地方application.html.erb是

<%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=AIzaSyCFm7OzAKuPbEa48b_aZ4S6JqMGVUCwwFs&libraries=places", async: true, defer: true %> 

..我怎麼混合兩個谷歌API腳本標籤?

回答

0

嘗試沒有在網址中使用回調initMap ..........

<%= javascript_include_tag "https://maps.googleapis.com/maps/api/js?key=AIzaSyCFm7OzAKuPbEa48b_aZ4S6JqMGVUCwwFs", async: true, defer: true %> 

希望這會爲你工作。謝謝!

+0

Got it!謝啦。如果你有另一個快速秒,請參閱我的編輯有關單獨的問題。 – fdsaevad