gmaps 未在 rails 4 + gmaps4rails 2.0.3 中定义

编程入门 行业动态 更新时间:2024-10-28 02:30:18
本文介绍了gmaps 未在 rails 4 + gmaps4rails 2.0.3 中定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Gmaps4rails 在 rails 4.0.0 中没有定义铁路谷歌地图我正在关注本教程rubydoc.info/gems/gmaps4rails/2.0.4/frames"

1) Gemfile宝石'gmaps4rails'2) 视图页面上的 HTML<div style='width: 800px;'><div id="map" style='width: 800px;高度:400px;'></div>

3)在查看页面<script src="//maps.google/maps/api/js?v=3.13&amp;sensor=false&amp;libraries=geometry" type="text/javascript"></script><script src='//google-maps-utility-library-v3.googlecode/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></脚本>您也需要 underscore.js,请参见此处:underscorejs/3) Javascript 源代码如果您有资产管道,请添加以下内容://= 需要下划线//= 需要 gmaps/google如果您没有资产管道,则需要导入 js 或 coffee 文件:rails g gmaps4rails:copy_jsrails g gmaps4rails:copy_coffee4)Javascript代码:创建您的地图:handler = Gmaps.build('Google');handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){标记 = handler.addMarkers([{纬度":0,"lng": 0,图片": {"url": "addons.cdn.mozilla/img/uploads/addon_icons/13/13028-64.png",宽度":36,高度":36},信息窗口":你好!"}]);handler.bounds.extendWith(markers);handler.fitMapToBounds();});

但是当我检查萤火虫时,它显示Gmaps 未定义"红宝石 2.0.0导轨 4.0.0gmaps4rails 2.0.3

任何建议请回复.....

解决方案

我遇到了这个问题.问题是我在加载核心 gmaps javascript 之前在视图中加载了地图构建 javascript.

您可以通过在您的 javascripts 之后添加一个 yield 并使用 content_for 块将您的地图构建 javascript 放在其他块之后来解决这个问题.像这样:

<script src="//maps.google/maps/api/js?v=3.13&amp;sensor=false&amp;libraries=geometry" type="text/javascript"></脚本><script src='//google-maps-utility-library-v3.googlecode/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></脚本><%= javascript_include_tag "application", "data-turbolinks-track" =>真%><%=产量:javascripts%>

然后,无论您在何处构建地图,

<script type='text/javascript'>handler = Gmaps.build('Google');/* 其余的地图构建 JS */<%结束%>

Gmaps4rails is not define in rails 4.0.0 Google Maps for Rails i am following this tutorial "rubydoc.info/gems/gmaps4rails/2.0.4/frames"

1) Gemfile gem 'gmaps4rails' 2) HTML on view page <div style='width: 800px;'> <div id="map" style='width: 800px; height: 400px;'></div> </div> 3) on view page <script src="//maps.google/maps/api/js?v=3.13&amp;sensor=false&amp;libraries=geometry" type="text/javascript"></script> <script src='//google-maps-utility-library-v3.googlecode/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script> You'll require underscore.js too, see here: underscorejs/ 3) Javascript source code If you have the asset pipeline, add this: //= require underscore //= require gmaps/google If you don't have asset pipeline, you'll need to import the js OR coffee files: rails g gmaps4rails:copy_js rails g gmaps4rails:copy_coffee 4) Javascript code: Create your map: handler = Gmaps.build('Google'); handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){ markers = handler.addMarkers([ { "lat": 0, "lng": 0, "picture": { "url": "addons.cdn.mozilla/img/uploads/addon_icons/13/13028-64.png", "width": 36, "height": 36 }, "infowindow": "hello!" } ]); handler.bounds.extendWith(markers); handler.fitMapToBounds(); });

But when i am checking at firebug its showing "Gmaps is not defined" Ruby 2.0.0 rails 4.0.0 gmaps4rails 2.0.3

Any suggestion please reply.....

解决方案

I ran into this issue. The problem was that I was loading the map building javascript in the view before I was loading the core gmaps javascript.

You can solve this by add a yield after your javascripts, and using a content_for block to place your map building javascript after the others. Something like this:

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

and then, wherever you're building your map,

<% content_for :javascripts do %> <script type='text/javascript'> handler = Gmaps.build('Google'); /* rest of maps building JS */ </script> <% end %>

更多推荐

gmaps 未在 rails 4 + gmaps4rails 2.0.3 中定义

本文发布于:2023-08-02 00:09:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1272930.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定义   rails   gmaps   gmaps4rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!