2015-04-17 30 views
3

我試圖插入一個gmap到我的網頁,不管我總是得到ReferenceError: Gmaps is not defined。這是我做了迄今:Rails 4:ReferenceError:Gmaps沒有定義

  • 添加gem 'gmaps4rails',跑捆綁安裝,重新啓動服務器
  • 添加下劃線到我的應用程序/資產/ JavaScript的文件夾
  • 添加//= require underscore //= require gmaps/google我的application.js
  • 編輯應用程序我查看HTML(下面的代碼)
  • 增加了一個叫做Gmap.js定製js文件到我的應用程序/資產/ JavaScript的文件夾(下面的代碼)

我application.html.erb(不僅僅是頭部):

<head> 
    <title><%= @page_title %></title> 
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> 
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> 
    <%= csrf_meta_tags %> 
    <script src="//maps.google.com/maps/api/js?v=3.13&amp;sensor=false&amp;libraries=geometry" type="text/javascript"></script> 
    <script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script> 
    <%= yield :scripts %> 
</head> 

我index.html.erb

<div class="col-xs-6"> 
     <div style='width: 800px;'> 
      <div id="map" style='width: 800px; height: 400px;'></div> 
     </div> 
    </div> 
    <br /> 
</div> 

我gmap.js

handler = Gmaps.build('Google'); 
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ 
    markers = handler.addMarkers([ 
    { 
     "lat": 0, 
     "lng": 0, 
     "picture": { 
     "url": "https://addons.cdn.mozilla.net/img/uploads/addon_icons/13/13028-64.png", 
     "width": 36, 
     "height": 36 
     }, 
     "infowindow": "hello!" 
    } 
    ]); 
    handler.bounds.extendWith(markers); 
    handler.fitMapToBounds(); 
}); 

我失去了一些東西明顯這裏?感謝您的幫助

這裏是整個事情的GitHub repo。相關文件名在帖子中。

+0

你不包括gmapsrails在你的資產 – apneadiving

回答

0

在你的佈局文件,確保您在該區間JS不是在頁腳

0

我只是碰到了同樣的問題,在我的application.js來到我需要底部的JavaScript在一定叫訂購。願這可以幫助別人

//= require vendor/underscore-min 
//= require gmaps/google 
//= require remastering/find_us