首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gmaps4rails版本2构建方法

gmaps4rails版本2构建方法
EN

Stack Overflow用户
提问于 2013-11-01 21:50:40
回答 3查看 2.5K关注 0票数 1

我为我的Rails应用程序安装了gmaps4rails,运行了生成器,并在我的application.js文件中要求像这样的两个文件,以及underscore.js

代码语言:javascript
复制
//= require underscore
//= require gmaps4rails/gmaps4rails.base
//= require gmaps4rails/gmaps4rails.googlemaps

按照github https://github.com/apneadiving/Google-Maps-for-Rails的指示,在layout.html.erb中添加这些依赖项

代码语言:javascript
复制
 <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>

当我试图用这段代码从github页面创建演示地图时,我发现了一个错误,即对象没有build方法。

Uncaught : Object #没有“构建”方法

代码语言:javascript
复制
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();
});

实际上,当我查看清单文件中所需的base文件时,该对象没有build方法。

如何在新版本的gmaps4rails中创建映射?

更新gmaps的github帐户是这样要求gmaps的,但是当我这样做时,“无法找到文件”gmaps/google“

代码语言:javascript
复制
//= require underscore
//= require gmaps/google
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-11-01 22:16:04

您应该在资产管道中使用这些要求。

代码语言:javascript
复制
//= require underscore
//= require gmaps/google

请记住,您需要手动添加underscore.js或使用gem才能使用它。

票数 4
EN

Stack Overflow用户

发布于 2013-11-06 12:56:36

对于错误:

代码语言:javascript
复制
couldn't find file 'gmaps/google'

我发现我只需要做一个包更新gmaps4rails,因为我一直在使用v1.5.6而不是最近的2.0.4。

票数 3
EN

Stack Overflow用户

发布于 2013-11-04 08:37:03

在您的应用程序目录中使用

代码语言:javascript
复制
rails g gmaps4rails:copy_js

代码语言:javascript
复制
rails g gmaps4rails:copy_coffee
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19735964

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档