我是 Ruby on Rails 的新手,正在尝试使用 gmaps4rails gem。经度和纬度自动显示,但地图没有出现。如果我查看页面源信息,似乎正在调用和创建地图,所以我不确定它为什么没有显示。这可以在这里看到:
<script src="//maps.google.com/maps/api/js?v=3.8&sensor=false&client=& amp;key=& amp;libraries=geometry&language=&hl=&region=" 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>
<script type="text/javascript">
Gmaps.map = new Gmaps4RailsGoogle();
Gmaps.load_map = function() {
Gmaps.map.map_options.auto_adjust = true;
Gmaps.map.initialize();
Gmaps.map.markers = [{"lat":40.8217303,"lng":-73.9551369}, {"lat":41.4925374,"lng":-99.9018131},{"lat":50.3429668,"lng":18.5540869}];
Gmaps.map.markers_conf.do_clustering = true;
Gmaps.map.create_markers();
Gmaps.map.adjustMapToBounds();
Gmaps.map.callback();
};
我是否需要在我的文档中包含一些其他文件才能显示地图?这些文件会在哪里?我正在使用 Ruby 1.9.3 和 Rails 3.2.12。我看到此类问题已被多次询问和回答,但我无法从这些答案中得到解决方案。谢谢你的帮助。
更新:
这是我的看法:
<br />
<%= link_to 'New Bathroom', new_bathroom_path %>
<%= gmaps4rails(@json) %>
模型:
acts_as_gmappable
def gmaps4rails_address
address
控制器:
def index
@bathrooms = Bathroom.all
@json = Bathroom.all.to_gmaps4rails
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @bathrooms }
end
end
和 application.html
<%= yield %>
<%= yield :scripts %>
<%= stylesheet_link_tag 'gmaps4rails' %>
</body>
</html>
我想知道的一件事是我是否需要将一些资产复制到应用程序。它在github网站上说。
"""""""""""""""""""""""""""""""""""""""""
gmaps4rails.css
将在您运行后复制到您的应用程序Rails 生成器。确保在您的第一步中需要此文件。
对于 Rails 3.0.x 或没有资产管道:
<%= stylesheet_link_tag 'gmaps4rails' %> """"""""""""""""""""""""""""""""""""""""" “”
由于我没有看到 gmaps4rails.css 文件,我想知道这是否是问题所在。感谢您的帮助。
发布调试器详细信息:
对,是真的。我几乎没有这方面的经验。我按照你的建议得到了 Firebug,发现当我在页面上滑动时,调试器中的谷歌脚本永远不会突出显示。我看到它确实尝试调用 googleapis.com 但是不同操作的时间为零,除了阻塞和等待。这让我觉得谷歌服务器没有发送任何内容。在 Get gmaps4rails.css 下,它在我的 app/asset 文件夹中查找并出现 404 错误。我正在学习如何理解所有这些信息,如果我是正确的,似乎服务器对谷歌的请求由于某种原因被阻止了,它认为我的 css 文件在资产文件夹中。如果我是正确的,我真的不知道从这里去哪里。请告诉我哪些信息有助于使这个问题更清楚。