【问题标题】:Rails, gmaps4rails problem with clustersRails,gmaps4rails集群问题
【发布时间】:2011-09-23 18:26:05
【问题描述】:

上次我注意到谷歌地图集群的问题。

我使用 gmaps4rails 插件(我尝试了 0.8.6 和 1.1.5 版本,两者都存在问题)。

一个标记的简单地图可以正确显示。

但如果我有 10 个标记,则不会显示地图(许多标记创建一个集群)。

我用萤火虫检查了这个问题,它返回

e.b.mapTypes[e.b.getMapTypeId()] is undefined

此错误来自文件 -> https://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer_compiled.js

此外,我尝试使用选项禁用集群

<%= gmaps({"markers" => { "data" => @json }, "map_options" => {"do_clustering" => false}}, true, true) %>

但我遇到了同样的错误。

有没有快速解决这个问题的方法??

【问题讨论】:

  • 我很抱歉,但我不明白这个问题:一张地图 + 10 个标记有什么问题?禁用集群有什么问题?
  • 是的,一张地图和 10 个标记有问题。当我禁用集群时,我得到了同样的错误。看起来 google maps api 的最后一次提交是“邪恶的”。 :)
  • 我从该主题中找到了可行的解决方案 -> stackoverflow.com/questions/7482233/… 但我无法回答我的问题,因为我的代表少于 100。错误是:e.b.mapTypes[e.b.getMapTypeId()] is undefinedthat.map_.mapTypes[that.map_.getMapTypeId()] is undefined。这取决于我包括哪个markerclusterer(第一个错误是markerclustered_compiled.js)。
  • 好的。在 1.1.6 中,我根据 gem 用户的要求更改了集群库。试一试!

标签: ruby-on-rails ruby-on-rails-3 google-maps gmaps4rails


【解决方案1】:

这是由于 google 的更新导致不兼容。

现在好了。

【讨论】:

    【解决方案2】:

    快速解决方案。

    下载此文件:

    http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/src/markerclusterer.js

    把它放进去:

    public/javascripts/markerclusterer.js

    并将第 90 行的代码更改为

      var maxZoom = 18; //that.map_.mapTypes[that.map_.getMapTypeId()].maxZoom;
    

    在 app/views/layouts/applications.html.erb 中包含文件

    <%= javascript_include_tag "https://maps.google.com/maps/api/js?sensor=false&libraries=geometry" %>
    <%= javascript_include_tag "markerclusterer_compiled.js" %>
    

    对于 0.8.x

     <%= javascript_include_tag "gmaps4rails.js" %>
    

    对于 1.x.x

     <%= javascript_include_tag "gmaps4rails.base.js" %>
     <%= javascript_include_tag "gmaps4rails.googlemaps.js" %>
    

    之后你必须使用:

     <%= gmaps4rails(@json, true, false) %>
    

     <%= gmaps({ "markers" => { "data" => @json } },true, false) %>
    

    不要从默认位置下载谷歌地图 JS 文件。

    来源:

    https://github.com/apneadiving/Google-Maps-for-Rails/wiki/View-helper

    ClusterMarkerer - no cluster appear - this.map_.mapTypes[this.map_.getMapTypeId()] is undefined markerclusterer.js:304

    HTH

    编辑 好的,谷歌解决了这个问题,但我会把解决方案留给其他人。

    【讨论】:

      猜你喜欢
      • 2015-12-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多